You were updating the sprite position every time it was drawn. pyglet
1.1 and newer work by calling the draw functions as often as
necessary, depending on how fast events are coming in. You want to
use the draw functions to just draw things, and call the update()
function separately using pyglet.clock.schedule_interval(func,
timedelta).
The function that pyglet.clock.schedule_interval calls gets an
argument dt that indicates how long has passed since the last call.
In the following code I've scheduled ship.update to be called 30 times
a second. It then moves the ship according to the dx and dy
variables, in proportion to dt. That way if your graphics card is
slow and can't handle 30 fps, the sprite will still move at the right
speed. If your graphics card can handle 200 fps, it will also move at
the right speed.
I also made your background into a kitten.
import pyglet
from pyglet import clock
from pyglet.window import key
MOV = 8
class GameWindow(pyglet.window.Window):
def __init__(self, x, y):
"""Initialising the game window"""
super(GameWindow, self).__init__(width=x, height=y)
self.set_caption("Test")
pyglet.clock.schedule_interval(ship.update, 1.0 / 30.0)
def on_draw(self):
self.clear()
background.draw()
ship.draw()
def draw(self):
self.sprite.blit(self.x, self.y)
def update(self, dt):
self.x, self.y = self.x + self.dx * dt * 30, self.y + self.dy * dt * 30
class Player(BaseSprite):
def __init__(self, x, y):
super(Player, self).__init__(x, y)
self.sprite = pyglet.image.load("ship.png")
def move_x(self, dx):
self.dx += dx
print "x is", self.dx
def move_y(self, dy):
self.dy += dy
print "y is", self.dy
class StaticSprite(BaseSprite):
def __init__(self, x, y):
super(StaticSprite, self).__init__(x,y)
self.sprite = pyglet.image.load("kitten.png")
if __name__ == "__main__":
background = StaticSprite(0, 0)
ship = Player(150, 150)
window = GameWindow(800,600)
pyglet.app.run()
--
Nathan Whitehead