Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Hitster

My game has tons of levels with a level select, Angry Birds style, and I don't want all the levels stored in the memory at once, especially since I plan to release it on mobile.

Currently I am trying to unload the previous level once either a level has been completed or the user goes back to the level select. But I cant get it v_v

//Back Button Here---------------------------------------------------------
		if (ig.input.pressed('escape')) {
			
			//delete backgroundMap.tiles;
			delete backgroundMap.tiles;
			delete ig.Image.cache['media/tiles.png'];
			delete LevelLvl1Resources[0];
			delete LevelLvl2Resources[0];
			
 // this is just a blank level I'm loading right now to put my level select on
			ig.game.loadLevel( LevelLvl0 );
			this.myDirector = new ig.buttonmanager()
		}
		//------------------------------------------------------------------------\\

1 decade ago by lTyl

You cannot remove data from memory directly. The delete operator removes a property from an object, but it does not remove anything from memory. (Although it does potentially mark an object for deletion from memory, but that only happens when the garbage collector kicks in)

Why can't you use a bunch of tiles or some other interactive objects on your level select screen which calls the appropriate level to load? When you switch between levels, the old level data exists in memory, but it should be marked for collection the next time the GC does it's sweep, which will then remove it from memory.

1 decade ago by Hitster

So if I load a new level the old level will be marked for garbage collection? And will that work the same way on mobile (as an app)?

1 decade ago by Joncom

When you load a new level, all the entities from the previous level will be destroyed and garbage-collected, however, the level tile-sheets and level-blueprint containing what tiles and entities go where, will remain in memory so that you can reload the previous level again later if you so choose.

Edit

I suspect that if you want to completely remove all traces of each level between level-changes, it will require some hacking. Removing ig.Image's from cache. Removing level file objects. Removing any ig.Sound's.

Is it truly important that you manage memory this way?
How big do you antiticpate your game getting?

The reason I ask, is because you may be surprised at how large of a game would be "OK" to have stored entirely in memory.
Page 1 of 1
« first « previous next › last »