You can subclass sprite to add an event handler: class Subclass(Sprite): def __init__(self, *args): Sprite.__init__(self, *args) window.push_handlers(self.on_mouse_press) def on_mouse_press(self, x, y, button, modifiers): print 'mouse pressed on sprite', self
Or you can dynamically attach an event handler to an existing sprite: sprite = Sprite(/*whatever*/) def on_mouse_press(self, x, y, button, modifiers): print 'mouse pressed on sprite', self import types sprite.on_mouse_press = types.MethodType(on_mouse_press, sprite, sprite.__class__) window.push_handlers(sprite.on_mouse_press) On Sun, Feb 22, 2009 at 6:16 AM, omcginnis <olive...@gmail.com> wrote: > > Hello, > > i'm a week into teaching myself pyglet (and python for that matter), > and i'm a bit stumped on something... is it possible to listen for > mouse events on specific sprites? I understand how to capture mouse > events via the default window handlers (i.e. on_mouse_press, > on_mouse_release, etc), but not on specific objects. I'm coming from > an AS3 background where you can attach mouse event listeners to > objects like this: someObj.addEventListener(MouseEvent.MOUSE_DOWN, > eventHandler). Is there a python/pyglet equivalent to this kind of > event handling? Basically, I want to create a sprite and have a > specific handler for when the user clicks on that sprite. Any > suggestions? > > Thanks very much. > > Ø > > > > -- Tristam MacDonald http://swiftcoder.wordpress.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to pyglet-users@googlegroups.com To unsubscribe from this group, send email to pyglet-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---