Hi, I want to control a sprite on the screen by using the arrow keys.
After looking at the examples, I was able to make such a program,
however, if I continue to press the arrow keys, it stops. I have to
keep releasing it and pressing it again to move the sprite. Is there a
way by which the sprite continues to move if I keep the key pressed?
Here is my code:

import cocos
from cocos.actions import *
import pyglet
from pyglet.window import key

class hello(cocos.layer.ColorLayer):

    is_event_handler = True

    def __init__(self):
        super(hello, self).__init__(0,0,0,255)

        self.sprite = cocos.sprite.Sprite("car1.png")
        self.sprite.position = (30,240)
        self.add(self.sprite)

    def on_key_press(self, symbol, modifiers):

        if(symbol == key.RIGHT):
            self.sprite.do(MoveBy((5, 0), 0.1)))
        if(symbol == key.LEFT):
            self.sprite.do(MoveBy((-5, 0), 0.1)))
        if(symbol == key.UP):
            self.sprite.do(MoveBy((0, 5), 0.1)))
        if(symbol == key.DOWN):


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" 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/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to