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

Managing recurring tasks


Loops can be found in any video game running in real-time. Small incremental steps generally characterize gameplay simulation code. With each of these steps occurs a minimal frame-by-frame change of object transformations, creating the illusion of smooth movement.

Panda3D has its own way of handling code that needs to be called time and time again while the game is running. This recipe's topic is Panda3D's task system.

Getting ready

Please complete the tasks found in Setting up the game structure found in Chapter 1 to get ready for this recipe.

How to do it...

Let's implement an application that uses the task system to execute a piece of code in every frame:

  1. Open Application.py and insert the following code:

    from direct.showbase.ShowBase import ShowBase
    from panda3d.core import *
    import random
    
    class Application(ShowBase):
        def __init__(self):
            ShowBase.__init__(self)
            self.smiley = loader.loadModel("smiley")
            self.smileyCount = 0
            self.cam...