0
我想創建一個精靈類和一個關鍵句柄來移動精靈,但它似乎並沒有工作。當執行時窗口會出現,但精靈不會。它出什麼問題了?Pyglet/Cocos2d,窗口出現,但精靈不會產生
import pyglet
import cocos
from pyglet.window import key
window = pyglet.window.Window()
keyboard = key.KeyStateHandler()
class Player(cocos.layer.Layer):
def __init__(self):
super(Player, self).__init__()
img = pyglet.image.load('../game/resources/sprite_1.png')
self.sprite = pyglet.sprite.Sprite(img)
def animate(dt, velocity, sprite):
sprite.position += dt * velocity
def on_key_press(self, symbol, keyboard, modifiers):
if symbol == key.RIGHT:
self.img.x += dt * 10
elif symbol == key.LEFT:
self.img.x -= dt * 10
elif symbol == key.UP:
self.img.y += dt * 10
elif symbol == key.DOWN:
self.img.y -= dt * 10
def on_key_release(self, smybol, keyboard, modifiers):
if symbol == key.RIGHT:
self.sprite.x = dt * 0
elif symbol == key.LEFT:
self.sprite.x = dt * 0
elif symbol == key.DOWN:
self.sprite.y = dt * 0
elif symbol == key.UP:
self.sprite.y = dt * 0
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)
pyglet.app.run()