Hi all,
Sorry for the long post. I am in the process of writing a game and have 20 levels so far (aiming for 60, will see how I go :), using it as an excuse to learn things I can teach to my students). I am designing the levels using Tiled and have written my own map engine (thanks to the guys on Corona Geek.) As the levels grow in complexity and size I have noticed the levels take longer and longer to load (although they seems to run OK on devices I have tested it on).
I am thinking that I might program in some tile management and have only the on-screen tiles loaded into memory (I think I will cache tiles as explained by Ed on Corona Geek), I hope that this will reduce loading time as less tiles will be ‘built’ at the start of the level.
I was wondering if anybody could give me some pointers here, I am fairly confident I can program it up, however I was wondering what the most efficient way of doing this would be? I would rather have a plan in mind before I go and make these changes. Currently I am thinking (if there is a more efficient method then please let me know)…
To build tiles I could…
- Cycle through the level data every frame and check if a tile is coming on screen and if it is build or pull from the recycle list the required tile.
or
- Somehow ‘read outward’ (not sure how to express this, or how it would be done) from the currently displayed tiles and build or recycle the required tiles, BUT stop when the ‘reading outward’ coordinates are too far off screen (as long as the tiles are in order then there should be no point in reading tiles that are beyond this point).
To recycle tiles I could…
- Cycle through the level data every frame and check if a tile is moving off screen and if it has add it to the appropriate recycling table.
or
- In the main loop I could dispatch a custom event that contains the boundaries of the current screen. Each built tile could listen for this and if the tile deems itself outside the current screen then it should; remove the listener, and then add itself to the appropriate recycling table.
I hope this is not too confusing… Thanks in advance for any help.
Craig