1. clock.schedule_interval(move, 1.0 / 6.0) instructs pyglet to call move each 1/60 sec ; that is repeat the call at 1/60, 2/60, 3/60,...
2. Every time a key is pressed the code in update will add a new request to call move with a 1/60 interval (pyglet don't cares it is the same function).
So, after pressing k times a key, move will be called k times after each 1/60
This problem is easy: move the line
pyglet.clock.schedule_interval(move, 1.0/60.0)
from the current location in update to just before the line
pyglet.app.run()
Then you can eliminate the function update from the code
Theres another problem with the code: each time move is called, it tells pyglet to record keypresses in KEYMAP.
So, after k calls to move, each keypress will be sent k times to KEYMAP.
That is a waste of CPU and memory.
Solution to this is easy: move the line
mainWindow.push_handlers(KEYMAP)
from move to just before the line
pyglet.app.run()
Notice that
@window.event
def on_key_press(symbol, modifiers):
a) eliminates all previously registered handlers for on_key_press events
b) registers the function as a handler for on_key_press events.
So, if you want to use
@window.event
def on_key_press(symbol, modifiers):
and
mainWindow.push_handlers(KEYMAP)
the later must be after the first in the code, or else the KEYMAP handler will be discarded.