How to store screen objects for a 2d side scrolling game?
I'm trying to 开发者_如何转开发figure out the best way to store map objects on a 2d side scrolling game.
For example, in the game Doodle Jump, how do the platforms you jump on get stored?
I've had a few thoughts about how it is possibly done..
Are the platforms stored in a string or other object that defines where each platform is going to be placed? For example if I defined a string like 0,10,5,8,6,2,3,4,2,..... and so on, I could interpret those as x-coordinates of each game piece in the game. I guess the problem with this is that could potentially be A LOT of game pieces to define. The game appears to be endless, so pre-defining the map seems like a bad idea.
I also thought that maybe the pieces are just random. So whenever the map calls for a new map piece, it randomly gets an x-coordinate. I thought this seemed pretty feasible but when playing DoodleJump it doesn't appear that they are all random.
Does anyone have any idea on how these map objects could be stored to lead me in the right direction?
Thanks!
I'm thinking an array of incremental height coordinates and their respective width coordinates (1d or 2d array). Incremental because of not letting the coordinates get to big.
You can use the screensize to know which platforms to calculate screen coordinates for. When the jumping object reaches a certain screenheight threshold, shift the camera with it, calculating new screen coordinates, omitting platforms that fall off screen and adding platforms that come within view.
You could generate the array beforehand using an algorithm with some randomness with a min/max constraint on coordinate distance. When using ints, you could generate a pretty big array before getting into trouble I guess.
Or generate it real-time using the same seed for the random function, so it will generate the same array every time and you can keep going indefinitely
You could use a random number generator with a fixed seed per level so users get the same level every time. The random numbers can select from an array of appropriate values. (I've used this successfully in an android game.)
A lot of platform games store the static map platforms (that is, the parts of the map that cannot be manipulated/destroyed - the floor tiles in Mario Bros., for example) as either predefined map. This can be done using an array of values or an alphamap image.
If you use the array method, use bytes (unsigned char
's) instead of int
's.
精彩评论