As well as making the object a state handler... you also need to handle the
key release, and have a timer to check the current state (are we rotating
left or right) and perform the action (which might be to call set_rotation
on the cannon..).
Perhaps something like:
class GameEventHandler(object):
def __init__(self):
self.rotation = 0
pyglet.clock.schedule_interval(self.update, 0.3)
def update(self, dt):
if self.rotation:
print "rotate %f"%(dt * self.rotation)
# or
# game.cannon.rotate(dt * self.rotation)
def on_key_press(self, symbol, modifiers):
if symbol == key.LEFT:
self.rotation -= 1
if symbol == key.RIGHT:
self.rotation += 1
def on_key_release(self, symbol, modifiers):
if symbol == key.LEFT:
self.rotation += 1
if symbol == key.RIGHT:
self.rotation -= 1
On Sun, Jun 21, 2009 at 10:20 AM, Ryan <[email protected]> wrote:
>
>
> This confused me too, at first. It did not seem to be anywhere in the
> docs.
>
> When you set up the game, do:
>
> keyboard = pyglet.window.key.KeyStateHandler()
> window.push_handlers(keyboard)
>
> Then use it like this:
>
> if keyboard[key.LEFT]:
> ....
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---