O'Reilly logo

Panda3D 1.6 Game Engine by Dave Mathews

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - collecting garbage from the Gun classes

Let's move right along to our Gun classes. These are created and destroyed with the cycles, so we need to make sure they are getting garbage collected properly.

  1. Open the GunClasses_00.py file from the Chapter12 folder. Update the imports section to use ExplosionClasses_02.py.
  2. Testing comes first, so put the following method at the bottom of the MachineGun class:
    def __del__(self):
    print("Machine Gun Removed")
    
  3. Then, put this method at the bottom of the Cannon class:
    def __del__(self):
    print("Cannon Removed")
    
  4. This time, resave the file as GunClasses_01.py. Open CycleClass_00.py and update the import to use Gunclasses_01.py, then resave the file with Ctrl+S and run the game. Click the New Game ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required