There are quite a few problems in your code which are preventing anything from happening:
You're creating a cocos2d entity within pyglet, without telling pyglet how to handle it. You're possibly better off using cocos2d for things like window creation etc.
You're creating a pyglet
Sprite
when you should probably be using a cocos2d one, and you're not attaching it to theLayer
.animate
isn't part of the API forLayer
(and even if it was, it would probably not be a static method).You haven't defined
Player
as an event handler, soon_key_press
etc won't do anything.You're passing more arguments into
on_key_press
etc than are required, and are referencingdt
without passing it in.
Here is a modified version of your sample code which should help you move forward:
import cocos
import pyglet
from pyglet.window import key
keyboard = key.KeyStateHandler()
class Player(cocos.layer.Layer):
is_event_handler = True
def __init__(self):
super(Player, self).__init__()
img = pyglet.image.load('../game/resources/sprite_1.png')
self.sprite = cocos.sprite.Sprite(img)
self.add(self.sprite)
def on_key_press(self, symbol, modifiers):
print 'pressing'
if symbol == key.RIGHT:
self.sprite.x += 10
elif symbol == key.LEFT:
self.sprite.x -= 10
elif symbol == key.UP:
self.sprite.y += 10
elif symbol == key.DOWN:
self.sprite.y -= 10
if __name__ == '__main__':
cocos.director.director.init()
player = Player()
main_scene = cocos.scene.Scene( player )
cocos.director.director.run( main_scene )