Beginner Panda3D and Python user in need of some help

Hi, I’m putting together a small game for a project and have about 3 weeks start to finish. I’ve got a pretty good understanding of C++, but the majority of what I’ve read advised against using it and learning Python instead

I’ve taken my time to read through the manual, and have a general understanding of:

-how task/event handling works
-how to load models, use the camera
-basic understand of python commands, hello world, etc and the like

The trouble is, I’m trying to get started putting together some simple programs so I can do the actual project, but I just cant seem to put it all together.

Here’s an example of my frustration:
I can make an event handler like so:

class EventHandler(DirectObject.DirectObject):
def init(self):
self.accept(‘mouse1’, self.printMouse1)
self.accept(“a”, self.printA)
def printMouse1(self):
print “You Pressed mouse1”
def printA(self):
print “You Pressed A”

but how would I make a task (running once per frame) to to execute this?:
def DoEvents(task):
#Code that “runs” the event handler each pass
return task.cont

I’ve gone through the manual regarding these parts. Maybe I’m just not reading it well enough, but it just isn’t sinking in.

Does anyone know a good tutorial or set of tutorials that involves a certain degree of hand-holding like the early part of the manual I can follow just to get a better feel for python with respect to Panda3D?

Thanks for your patience

Your class, such as you’ve designed it, has no part of it that needs to run every frame. Simply create an instance of it, then call run() and sit back and watch your “event handler” respond to events.


Maybe this is what you are looking for:

class EventHandler(DirectObject.DirectObject):
  def __init__(self):
    self.accept('mouse1', self.printMouse1)
    self.accept("a", self.printA) 
    taskMgr.add( self.DoTasks, 'some funny name for your task' )

  def DoEvents(self, task):
    #Code that "runs" the event handler each pass
    return task.cont

  def printMouse1(self):
    print "You Pressed mouse1"

  def printA(self):
    print "You Pressed A"