开发者

how to deform image?

开发者 https://www.devze.com 2023-02-21 05:22 出处:网络
Hi Friends I Want to make a simple gaming Application in 开发者_开发百科which the user hit the car and car breaks from that point means the image get little deformed when the user hit the car image.

Hi Friends I Want to make a simple gaming Application in 开发者_开发百科which the user hit the car and car breaks from that point means the image get little deformed when the user hit the car image. I know everything could be possible with using of lots of images and get change when user hit that car image but i don't want to use so many images.

is there any solution for this , how can i deform the image ..sorry for my English but , here i paste a link of the game that is on flash and this is what i exactly want..

http://www.playgecogames.com/file.php?f=657&a=popup

please respond soon thanks


You don't say if this is in 2D or 3D, or what techniques you're going to use.

If you're implementing the game using OpenGL, it's fairly straightforward. The object can be made up of a regular mesh, with the image as a texture mapped to the mesh. When the user hits the object, you just deform the mesh.

A simple method would be to take a vector in the direction of the hit, displace the nearest vertex by an amount proportional to the force of the strike, and then fan out in to deform the rest of the mesh in decreasing amounts. By deforming the mesh, the image texture will be rendered with all the dents or deformations you like.

If you want to to this without OpenGL and just straight images, you could use image resampling to simulate the effect. You have your original pristine image which is 'filtered' to make up the resulting image. At first there are no deformations so you copy the original image verbatim. Each time the user hits the object, you can add a deformation using a filter or transform within a local region of interest. This function would resample the source image in a distorted manner, causing it to look like the object is damaged.

If you look up some good books on game development, you'll find a great range of approaches to object collisions, deformations and so on.


If you know a bit about image processing technics here is the documentation for accessing the pixels of the image : Apple Reference

You also have libraries for this such as this one :
simple-iphone-image-processing

But for what you want to do this might not be the easiest way. What I would suggest is that you divide the car into several images depending on what areas can be impacted. Then you just change the image corresponding to the damaged zone each time the car is hit.


I think you should use the cocos2d effects http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide%3aeffects + multiple images. Because there are many parts which drops after the player kick the car. Like when user kick the side mirror you should change the car image with without side mirror car image.


The person that has made that flash game used around 4 images to display the car. If you want the game to be in 2d, the easiest way is to draw the car, cut it into about 4 pieces (: left side + right side (duplicate of the left side) hood and roof).

If you want to "really" deform the car you'll have to use a 3d engine like openGLES.

Id really suggest doing it in 2d :)


I suggest having a look at the cocos2d game engine. You can modify images with effects, which are applied using a virtual grid. Have a look at the effects page in their programming guide.

0

精彩评论

暂无评论...
验证码 换一张
取 消