Closed shazz closed 4 years ago
Wasabi2d detects the parameters that a handler function takes and passes the attributes of the Pygame event object. So it cannot handle a method, because it doesn't know about self
.
The event mapper could easily be adapted to accept classes and methods. Perhaps a method like
w2d.map_events(MyGameClass())
Yes, it would be great to support methods as a well organized game design will quickly require to define multiple classes of objects.
Else, if there is an explicit way to register a method as a callback for events, that would work too :) Decorators are nice but not mandatory, good to have both in my opinion.
The workaround is to create event hooks that dispatch to the current game class instance:
current_game = Game()
@w2d.event
def on_key_down(key):
current_game.on_key_down(key)
Hi,
In my class, I added a method to manipulate my wasabi objects (class variables)
but I got this error:
AttributeError: 'Event' object has no attribute 'self'
Thanks!