Last month, I experimented a lot in game development using cocos2d for the iPhone, especially on moving and modifying sprites. However, vertices and polygons are still new stuff for me.
I developed an algorithm that creates a set of points. I now want to use them to create my 2D terrain. Here is how it looks like when I connect the points in java, so that you can get the idea
The points are connected with lines. However a real game terrain is a shape that is colored or has a texture overlayed, right? For example:
How could I use my points to create such a terrain?
What I tried so far is I created an array and filled it with my points. I pass this array to this method
void ccDrawPoly ( const CGPoint * vertices,
NSUInteger numOfVertices,
BOOL closePolygon
)
draws a poligon given a pointer to CGPoint coordiantes and the number of vertices measured in points. The polygon can be closed or open
This actually draws a plain shape. But from the blue picture it looks like there is not one shape but many.
Please share you knowledge on how to create 2d game terrain.
Update 03.06.2011
Based on the two good answer I have following result
Answer
The easy/naive solution would simply be to take your existing points, and for each point have a corresponding point that's at the same Y position but off screen. From there, create your polygon by taking, say, points 0, 1, 1's pair, and 0's pair and pass that to your DrawPoly method. Then continue on with (1, 2, 2's pair, 1's pair), etc.
No comments:
Post a Comment