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

Loading and attaching sounds to objects


In this recipe we will take a look into Panda3D's positional audio capabilities. 3D sound is a wonderful tool to immerse the player and to generate great atmosphere. Positional audio also can help the player to orientate: In a shooter, for example, it is much easier to return fire if one heard that the enemy units are attacking from behind.

Getting ready

Before starting this recipe, be sure to set up a project as described in Setting up the game structure. You will also need to provide a mono sound file called loop.wav in the sounds folder of your project.

How to do it...

Let's load a sound file and attach it to a model:

  1. Open Application.py and add the highlighted code:

    from direct.showbase.ShowBase import ShowBase
    from direct.showbase.Audio3DManager import Audio3DManager
    
    class Application(ShowBase):
        def __init__(self):
            ShowBase.__init__(self)
            self.smiley = loader.loadModel("smiley")
            self.smiley.reparentTo(render)
    
            self...