开发者

Storing spawn information for 2d platformer/scroller

I'm looking for some idea's how best to store spawn information for a side scroller. The game I'm writing is very similar to Super Mario Bros. What I'm trying to implement is as you move through a level, enemies should spawn at particular locations. I want to store t开发者_开发技巧his information in the level and I don't want to just randomly spawn enemies. I'm looking for a high level strategy to store and retrieve the spawned objects when the player reaches a particular location (like mario). I couldn't find any decent tutorials or suggestions from Googleing around.

The Level is tile based so the map is Tile[][]. Each tile right now is 16x16 pixels.

The only good suggestion I've seen so far is to store the the spawning information in a 2d array where the first dimension is x and the second is y, given in tile space. The issue I have with that implementation is that if my player is at say (160, 0) I want to spawn a particular enemy. If however next time the level is reset the player is at (160, 5) I want to spawn the same enemy. So for that implementation to work I have to do a scan for a given y position.

I'm looking for a more efficient storage mechanize. I need something where I can retrieve the correct spawns quickly and not waist too much memory storing spawning locations.

Are there any common strategies in games for this?


As long as there are not too many spawn-points, a simple list will do. Each list entry has the XY coordinates and spawn info. Just iterate through the list to determine whether player is near a spawn point. This is much more memory efficient than a sparsly filled 2D array, very easy to implement, and probably fast enough.

If it turns out to be not fast enough you need some kind of spatial index, kd-trees are rather simple to implement and offer good performance for proximity search. Another solution is to use a locality sensitive hash, as explained in this paper (PDF).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜