Book Image

Panda3D 1.7 Game Developer's Cookbook

Book Image

Panda3D 1.7 Game Developer's Cookbook

Overview of this book

Table of Contents (20 chapters)
Panda3D 1.7 Game Developer's Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling events more elegantly


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.

Getting ready

Follow the tasks of Setting up the game structure found in Chapter 1 prior to continuing with the current recipe.

How to do it...

The following are your tasks for this recipe:

  1. Add a new file called GameObject.py to your project.

  2. 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...