Restarting My Game [SOLVED]

Hey everyone,

I’m making a game modeled closely after the old Atari game “Tank”. I’ve got my game-play down, but I need a way to restart it. I’m having trouble totally clearing the scene graph so the game effectively starts over. Is there a way to clear all nodepaths parented to render in one fell swoop, or is there another good method to do this? Everything I’m working with is procedurally generated geometries, no models (no time to learn blender!). I’ve seen suggestions that I need to destroy the instance of my gameWorld and create a new one, but I don’t know if I can do that within the script. Any help would be greatly appreciated!

Brian

Update: I think… that I effectively want to restart my script from within the script… So not necessarily a panda3d thing, more of a Python thing. Any pointers?

I see two questions to answer here:

  1. Clearing the nodes below render:
    The simplest way might be to place a NodePath of your own (let’s call it “gameRoot”) directly below render, remove it (using the “removeNode” method) each time the game ends and create it each time the game starts.

  2. Resetting your game:
    I suggest having two classes: a “framework” class that controls the flow of your game, and your “level” class that handles your moment-to-moment game logic–the class that you have at the moment.

Your “framework” class would then keep an instance of your “level” class. When the game starts, create a new instance of the “level” class and assign it to the variable in your “framework” class. When the game ends, destroy the “level” instance (and perhaps assign the variable to “None”).

You might consider giving your “level” class a “destroy” method that is called when you remove the instance, and which performs whatever cleanup is called for, such as removing the nodes below “render”.

It works!! I created a gameRoot NodePath and reparented it to render. At the end of the game, I called removeNode() on it and created a new gameRoot NodePath, effectively clearing everything that I had rendered! Perfect!

Thanks so much!
Brian