开发者

Getting pixels data from image on iPhone

I want to use bitmap images as a "map" for levels in iphone game. Basicly it's all about the location of obstacles in the rectangular world. The obstacles would be color-co开发者_运维问答ded -- where the white pixel is, there's no obstacle. Black means there is one at this point.

Now I need to use this data to do 2 things: (a) display the level map, (b) for in-game calculations. So, in general, I need a way to read the data from the bitmap and create some data structure (matrix-like) with those information - to both overlay the bitmap onto the level graphics as well as to calculate collisions and such.

How should I do it? Is there any easy way to read the data from image? And what's the best format to keep the images for this?


Have you looked at how Texture2D translates an image file to an OpenGL Texture ?

Tip: take a look at this Method in Texture2D.m:

- (id) initWithCGImage:(CGImageRef)image orientation:(UIImageOrientation)orientation sizeToFit:(BOOL)sizeToFit pixelFormat:(Texture2DPixelFormat)pixelFormat filter:(GLenum) filter

In 3D apps, it's quite common to use this kind of representation for height maps, in a height map, you use a Texture with colors that range from black to white ( white represents the maximum altitude )

For example, from this:

Getting pixels data from image on iPhone

To this:

Getting pixels data from image on iPhone

That was just to tell you that your representation is not that crazy :).

About reading the bitmap, I would also recommend you to read this (just in case you want to go deeper)

Hope I helped a bit!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜