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 and using a key map

  1. The first step to using a key map is to actually create the dictionary that serves the purpose. Right after the line that calls self.cycle.setPos() method in the __init__ method, insert the following block of code to create the dictionary:
    self.keyMap = {"w" : False,
    "s" : False,
    "a" : False,
    "d" : False}
    
  2. Now we need to register events for the four keys in our key map. Replace the current self.accept() call, with the following code:
    self.accept("w", self.setKey, ["w", True]) self.accept("s", self.setKey, ["s", True]) self.accept("a", self.setKey, ["a", True]) self.accept("d", self.setKey, ["d", True]) self.accept("w-up", self.setKey, ["w", False]) self.accept("s-up", self.setKey, ["s", False]) self.accept("a-up", ...

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