Yes Ill move the position of the clock schedule line and also I want to remap my keys every time as I will have different functions for the keys - in case of main menu, level's of the game. If theres a better way that this please do tell me.
Thanks a lot :) On Sunday, 17 March 2013 12:27:29 UTC+5:30, claudio canepa wrote: > > > > On Sat, Mar 16, 2013 at 7:13 PM, Pranav Salunke > <[email protected]<javascript:> > > wrote: > >> Hey Guys, >> >> I made a simple prototype for my own testing of Pyglet and I found one >> weird bug in my code which I could not nail no matter how many times I go >> through the same. The bug is that the speed of the moving sprite gradually >> increases and the sprite gets faster and faster as the number of clicks >> increase. Is there any suggestion as what may be causing this. Thanks a lot. >> >> >> >> >> I have attached the Tar Ball containing the code. >> >> Regards, >> Pranav >> > > > > 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. > > > -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pyglet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
