i am using AndEngine.
I have a scene that i would like to reuse for all of my levels.
The only thing that will change is the objects loaded on the scene through a method i created to load the level.
The problem i am facing is that at the end of the level the user gets the option to continue to the next level. I allow the user to load the next level with this method.
this.nextlevel = new Sprite(0,0,150,80,this.nextLevelRegion,this.getVertexBufferObjectManager()){
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
final float pTouchAreaLocalX,
final float pTouchAreaLoca) {
GameScene.detachChildren();
loadLevel(level);
return true;
}
};
The loadLevel(int level_number) takes a int as a parameter. I increase this variable by level++; after the current level is loaded.
The problem is when the sprite is clicked it keeps adding +1 to the level integer and trying to load the wrong level..
Anyone know a better way of doing this?
this is what i did in my game:
i created a class that creates the game play scene, this class has a method that creates the scene and loads an XML level based on the number that it recieves when i call it.
when i want to go to next level i get the current level number (lets say its x) and call the method with x+1 as an attribute for it.
you should note that i depend in this method on recreating the scene all over again so you should reset every thing when you do that.
this is the call for the method:
and here is the link for my game if you want to see how that works:
https://market.android.com/details?id=com.ayham.blowangryshapes
i only have one game play scene in the game and the levels are loaded as needed.