To better understand NodePaths
, let's go ahead and use the print statement to take a closer look at what's going on.
At the end of the
__init__
method in our world class, add this line:print(self.track)
Make sure it's part of the indented block that makes up the method.
Save the file as "
chp02_04.py
" and run it. Look at the command prompt window to see the output of theprint
statement.Note that at the bottom it says "render/Track.egg" in a format that looks just like a file path. That's because "render/Track.egg" is the model's location in the Scene Graph. Whenever we print out a
NodePath
, we'll get a result like this.Next, change the
print
statement to look like this:Save the file as "
chp02_05.py
" and run it.Now the output says "ModelRoot Track.egg". The
ModelRoot
is the node that theself.track NodePath
points to.