O'Reilly logo

Panda3D 1.6 Game Engine by Dave Mathews

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating background music

Enough talk, action speaks louder than words. Let's add some background music to our game.

  1. Open WorldClass_00.py from the Chapter11 folder.
  2. Scroll down to the bottom of the __init__ method and add the following four lines of code there:
    musicMgr = base.musicManager
    self.music = musicMgr.getSound(
    "../Sound/Loveshadow-Takin_Yo_Time_(The_Wingman_Mix).wav")
    self.music.setLoop(True)
    self.music.play()
    
  3. Resave the file as WorldClass_01.py and run it from the command prompt.

What just happened?

Now we've got music! That's all there was to it. We just loaded the sound file into the AudioManager with getSound, set it to loop with setLoop(True), and told it to play with the play method.

The song we loaded is called ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required