For my game, Im using
- libGDX
- Ashley (ECS)
- Box2D
Ive got a lot of screens but for simplification: MainMenuScreen
and InGameScreen
.
In InGameScreen Im init the ECS (Ashley) and create a lot of entities. Some have PhysicsComponent. The PhysicsSystem will catch them and call Box2D to spawn some objects based on the parameters within the PhysicsComponents.
So far so good.
Now, when the player dyes, I run setScreen(new MainMenuScreen());
from my "Main"-Class (MyGame.java).
- the game starts and
MyGame
loading at first theMainMenuScreen
- than the
InGameScreen
will get loaded (when player presses a key) - than the player dyes
MyGame
recognized it and loading again (throu callingsetScreen(...)
) theMainMenuScreen
- When Player press key:
MyGame
loading another round (setScreen(new InGameScreen)
)
I guess I have to do something like a complete clean up between switching screens. But how should I implement this? Just "deleting" the old InGameScreen-Object shouldent be enought, right?
- Do I have to use the
dispose()
-Method? - Is it enough to instantiate everything new (in the
init
fromInGameScreen
) since it will instantiate all child-object new for its own likeBox2DWorld world = new World();