Shoot, I completely missed your response. You've probably either figured this out by now or abandoned this, but the answer is that custom clocks don't tick themselves! You have to make the custom clock tick by calling c.tick()
Adding the following line to your file right above pyglet.app.run() should make your code behave like you expect: pyglet.clock.schedule(lambda dt: c.tick()) ~ Nathan On Sat, May 11, 2013 at 6:11 PM, <[email protected]> wrote: > #!/usr/bin/env python# -*- coding: utf-8 -*- > import pyglet > class Clock(pyglet.clock.Clock): > def __init__(self): > super(Clock, self).__init__() > class Test(object): > def update(self, dt): > print dt > > w = pyglet.window.Window()@w.eventdef on_draw(): > w.clear() > > t = Test() > > > c = Clock() > c.schedule_interval(t.update, 1/60.0) > > pyglet.app.run() > > Sorry, this is the code. My problem is this code doesn't print dt and my > clock object doesn't tick. > > El lunes, 6 de mayo de 2013 01:47:46 UTC-3, Nathan escribió: >> >> You aren't using your custom class in the first example (???) >> >> c = pyglet.clock.Clock() >> >> >> ~ Nathan >> >> >> On Wed, May 1, 2013 at 5:13 PM, <[email protected]> wrote: >> >>> I want to subclass Clock class of pyglet.clock module, but I have some >>> troubles when I use schedule_interval: >>> >>> The following code doesn't print anything and the object c looks like if >>> not ticked at all: >>> >>> #!/usr/bin/env python# -*- coding: utf-8 -*- >>> import pyglet >>> class Clock(pyglet.clock.Clock): >>> def __init__(self): >>> super(Clock, self).__init__() >>> class Test(object): >>> def update(self, dt): >>> print dt >>> >>> w = pyglet.window.Window()@w.eventdef on_draw(): >>> w.clear() >>> >>> t = Test() >>> >>> c = pyglet.clock.Clock() >>> c.schedule_interval(t.update, 1/60.0) >>> >>> pyglet.app.run() >>> >>> But the next works fine. >>> >>> #!/usr/bin/env python# -*- coding: utf-8 -*- >>> import pyglet >>> class Clock(pyglet.clock.Clock): >>> def __init__(self): >>> super(Clock, self).__init__() >>> >>> pyglet.clock.set_default(self) >>> class Test(object): >>> def update(self, dt): >>> print dt >>> >>> w = pyglet.window.Window()@w.eventdef on_draw(): >>> w.clear() >>> >>> t = Test() >>> >>> c = Clock() >>> c.schedule_interval(t.update, 1/60.0) >>> >>> pyglet.app.run() >>> >>> The only difference is the pyglet.clock.set_default(self) sentence in >>> the constructor method of Clock. >>> >>> I think this is not clear or, at least, is not the best way of >>> subclassing pyglet.clock.Clock to have your own derived Clock class. >>> >>> *The questions:* >>> >>> There is some way to set the default clock automatically with Pyglet? >>> >>> There is a solution more elegant or pythonic? >>> >>> Is possible do this without the pyglet.clock.set_default(self) line? >>> >>> -- >>> 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 pyglet-users...@**googlegroups.com. >>> To post to this group, send email to [email protected]. >>> >>> Visit this group at >>> http://groups.google.com/**group/pyglet-users?hl=en<http://groups.google.com/group/pyglet-users?hl=en> >>> . >>> For more options, visit >>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >>> >>> >> >> -- > 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. > > > -- 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.
