I have a game with two main states: with a menu open and with it closed. I
switch between these two states by popping one set of handlers and pushing
the other (and turning a visible flag on and off on the menu elements, and
unscheduling or scheduling my update functions). However, I've found that
when I pop the handlers the following happens:
- scheduled updates don't occur
- event handlers don't trigger, including on_draw (custom mouse cursor is
frozen in one place, animations are frozen)
This continues until I press a key or click the mouse. Using win.activate
does nothing. I attached a toy script the demonstrates the problem.
Thanks for any help!
-Josh
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
import pyglet
from pyglet.window import key, mouse
class MyAHandler:
def __init__(self):
pass
def on_key_press(self, symbol, modifiers):
if symbol==key.A:
print 'A'
pass
class MyMouseHandler:
def __init__(self):
pass
def on_mouse_press(self, x, y, button, modifiers):
if button==mouse.LEFT:
print 'B'
pass
class Master:
def __init__(self, window):
self.window = window
self.a = MyAHandler()
self.mouse = MyMouseHandler()
def on_key_press(self, symbol, modifiers):
if symbol==key.F10:
self.window.pop_handlers()
self.window.push_handlers(self.mouse)
elif symbol==key.F9:
self.window.pop_handlers()
self.window.push_handlers(self.A)
def start_game():
global on_draw, frame
win=pyglet.window.Window(400, 400)
mouse_pic = pyglet.resource.image('mouse.png')
mouse = pyglet.window.ImageMouseCursor(mouse_pic, 0, mouse_pic.height)
win.set_mouse_cursor(mouse)
handler = Master(win)
fps_display = pyglet.clock.ClockDisplay()
def on_draw():
win.clear()
fps_display.draw()
def frame(dt):
win.clear()
pyglet.clock.schedule(frame)
win.push_handlers(on_draw)
win.push_handlers(handler)
win.push_handlers(handler.a)
pyglet.app.run()
if __name__=='__main__':
start_game()