Re: Problem with Clock

41 views
Skip to first unread message

Nathan

unread,
May 6, 2013, 12:47:46 AM5/6/13
to pyglet...@googlegroups.com
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, <superu...@yahoo.com.ar> 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.event
def 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.event
def 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 pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nathan

unread,
Jun 28, 2013, 8:09:15 PM6/28/13
to pyglet...@googlegroups.com
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, <superu...@yahoo.com.ar> 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.event def 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.
Reply all
Reply to author
Forward
0 new messages