Although Panda3D's event system is a great way for passing messages between objects, there are some things you should know before you are going to use it in your game. This recipe will show you an even more elegant way of integrating events into your code. You will learn how to use the introspection facilities of the Python language to create an annotation that marks a method as an event handler. Additionally, this article will discuss some problems you might encounter when using the messaging system of Panda3D.
Follow the tasks of Setting up the game structure found in Chapter 1 prior to continuing with the current recipe.
The following are your tasks for this recipe:
Add a new file called
GameObject.py
to your project.Insert the following source code into
GameObject.py
:from direct.showbase.DirectObject import DirectObject def handle_event(event): def inner_event(func): func.event_name = event return func return...