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 - making and importing a custom class

To start with, we're going to make a simple class for the track in our game and import it into our main file.

  1. Start by opening up the file chp04_07.py and resave it in the Chapter05 folder as WorldClass_01.py.
  2. Next, open a new blank document in Notepad++ and save it as TrackClass_01.py.
  3. In the new file, add the following lines of code at the very top:
    class Track:
    def __init__(self):
    
  4. The next step is to copy a few lines from WorldClass_01.py, specifically the lines where we load our track, reparent it, and reposition it. Once you've copied the lines to the clipboard, you can delete them from the WorldClass_01.py file. These are the lines we're referring to:
    self.track = loader.loadModel("../Models/Track.egg") ...

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