Level part changing in an entity system based game

420 Views Asked by At

I am currently working on an entity system based game using artemis and libgdx and I am wondering how I should handle level changing in such a configuration.

For example, with a Mario-like platformer:

First Mario starts the level, the engine instantiates a new World() loading the tilemap and initializing all the objects.

What if Mario goes through a pipe? The world inside the pipe is a new World()? or does the camera only focus on another part of a world?

If we have a new world, artemis doesn't allow detaching an entity from a world, so may I clone the player entity and add it to the new world?

Does someone know how to handle this kind of level part changing (Mario's part / Abe's odyssey screens)? What are the common ways to achieve this using an artemis-like framework?

3

There are 3 best solutions below

0
On BEST ANSWER

I finally decided to add a room object layer defining rectangles (see picture below)

room layer above the tile map

Each room is a rectangle with it's x, y coordinate and width, height dimensions. Each room defined the bounds where the camera is allowed to move, if the player intersect with another room, the camera slide from room n to room n+1 along the x axis or the y axis, if the room is bigger than the screen, the camera is allowed to scroll.

I have been able to improve performance and to solve a lot of issues using this approach, it is possible to only process the entities contained within the current room instead of calculating the full world at each frame.

0
On

I would create some LevelTagComponent and add it to all entities that are level-specific. Custom Manager should do the rest - turn off some entities when Mario goes into a tunnek or remove them when level is being completely changed.

1
On

Think about decoupling the building of each particular level so that your world object can take in a specific level that could either read in the position of entities like the mario blocks and pipes or just define them in that specific level class. Allow your world to set new level as a method or you could create a new world object each time and unattach the old one for garbage collection. For something like the world in the pipe if you didn't want to have to load it while the player was already in the level than you could build the room or area somewhere off in the distance and use the pipe to teleport the character to a spot inside the room.