How To Implement Multiple Levels?

Hi! One beginner’s problem I have noticed that is never addressed is the issue of levels. The examples that I have seen usually take place in one World(), or, if they have multiple levels, usually they are just rearrangements of the same World().

What I want to do is to load 2 or more different World() classes with different scenery models, and possibly different actors, depending on the story in the game.

My question is: Let’s say you have more than World(), World1() and World2(), and that you would like them to load in a Start Screen. In a typical start screen, you call up your first (and only) world level with no problem. But how do you do it with more than one? What is the setup? How do you keep the libraries from getting mixed up, to prevent World2() loading instead of World1(), or the Level Choose screen not come up at all?

If anyone could help me with this problem, I will gladly put up an official version of the code in Code Snipplets for beginners to look at, since I believe level switching is probably the most important aspect of a game. I plan to make some sort of official Panda3D-template for everyone else to use.

Thanks in advance!!! :smiley: :smiley: :smiley: :smiley:

Good question. This is an issue that people never really talk about. I had to figure out a way to do it.

Look at this :

I do level switching there- I call them ‘missions’ they are in a missions folder and the program loads up the correct one based on where the player is in the game. Updating the function that chooses which level to load so that the player can replay old missions is my next task.

This isn’t to say it’s the only way to create levels. It’s one that works for my program. I think in the showcase section there is another program with levels called the Rez Clone. It uses XML instead of .py modules but it gets the same this done as far as levels go.

There are many ways to load levels for your game, depending on what you want.
The important part to switch levels is to include a way of unloading a level that has been loaded, to free up the scene graph for the content of the new level.

It’s helpful to reparent every level geometry to a common level node, so that you can go through the nodePath under your level node and remove all the nodes there to unload the geometry of the level.

You basically just need to keep track of everything level specific that you load and provide an unload function for that. Then a level switch is just a call to the unload function plus another call to the load function to load a new level.


I am creating an adventure game with several scenes (rooms). What I
have done is to create a Room Manager (sort of dictionary of rooms) and to
have a pointer to the current room, in your case, worlds. When the current
actor walks from one room to another room, the game engine calls the
exit() method of current room and, after that, to the enter() method of new
room. These methods deal with reparent / de-reparent (?) (show/hide)
objects to render object.
In addition, there are exits (as objects) that connect both rooms. The exits
contain the position and orientation of the actor in the new room. At any
moment, only visible room, objects and actors are re-parent to the render.
Every change of room implies reparent / de-reparent panda nodes to render.
By the way, the room is the base of all rooms, which contains the
common methods. Every scene (concrete room) is specialized python
class for that scene. Mainly, each scene redefines the enter() and exit()
I hope this help.

Thank you for the replies. I have looked through some of the panda examples I have downloaded and now I understand them a bit better.
And Mavasher, thank you very much for posting your example in the other parts of the forum; I have downloaded it and am using it help my further learning.