I have developed an algorithm that generates 2D terrain coordinates for my iOS 2D game. This may be a possible visual output:
The coordinates are stored in a 2D array.
mVertices[i] = ccp(sx, sy); mVertices[i] = ccp(sx, 0);
sx is increased in steps of
i is the number of steps. For each step a
sy is generated. To get the line straight down I need a second point which is the second line of code.
Imagine in the game there will be a character on that terrain. The terrain scrolls to the left while you have to move your character. Now I want to figure out what would be the best way for me to draw the terrain.
One way is to pre-load the terrain. So I would generate the points for say 5000px along the x-axis when the user starts the game while a loading spash is displayed.
Another way is to generate the terrain in real-time. I think this is the best solution here. What do you think?
When I take the real-time way, how I do the array stuff? I mean the part that goes out of screen has to be removed from the array and there is a new step that is added.
Maybe a classic array is not good as data structure for that prupose. I introduced it in my project because I can pass it to the
ccDrawPoly function that takes a
Please share your ideas.