I've tried to use it, but function scheduling seems to not be working with 
that custom clock.
Used following code, but while pyglet.clock scheduled events occur, 
TestClock scheduled ones do not...
What's wrong with it?

import pyglet

class TestClock(pyglet.clock.Clock):
    __time = 0
    speed = 1.0

    def __init__(self):
        pyglet.clock.Clock.__init__(self, time_function=self.get_time)
        pyglet.clock.schedule(self.advance)

    def advance(self, time):
        self.__time += time * self.speed

    def get_time(self):
        return self.__time
    
    def set_speed(self, dt=0, speed=1.0):
        print "Set speed", speed
        self.speed = speed

class A(object):
    def __init__(self):
        self.clk = TestClock()
        self.clk.schedule_interval(self.te, 0.3)
    def te(dt=0.0):
        print "TEST", dt
    def up(self, dt):
        print 'up'
 
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
                          font_name='Times New Roman',
                          font_size=36,
                          x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')
@window.event
def on_draw():
    window.clear()
    label.draw()
        
def x():
    print "X"
        
testobj = A()

pyglet.clock.schedule_interval(testobj.up, 1/6.0)
testobj.clk.schedule_once(x, 2)

pyglet.clock.schedule_once(testobj.clk.set_speed, 5, speed=10.0)

pyglet.app.run()

W dniu środa, 6 marca 2013 23:52:10 UTC+1 użytkownik Petr Viktorin napisał:
>
> You can use something like this: 
>
> class AdjustableClock(pyglet.clock.Clock): 
>     __time = 0 
>     speed = 1 
>
>     def __init__(self): 
>         pyglet.clock.Clock.__init__(self, time_function=self.get_time) 
>         pyglet.clock.schedule(self.advance) 
>
>     def advance(self, time): 
>         self.__time += time * self.speed 
>
>     def get_time(self): 
>         return self.__time 
>
> ..and use an instance of that clock everywhere (except e.g. animations 
> in the pause menu). 
> To pause, set the clock's speed to zero. 
>
>
> On Wed, Mar 6, 2013 at 11:33 PM, Winston Wolff 
> <winsto...@cal.berkeley.edu <javascript:>> wrote: 
> > I don't know off the top of my head but I know that cocos2d ( 
> http://cocos2d.org ) implements pause, and it uses Pyglet. You could 
> investigate that. 
> > 
> > -ww 
> > 
> > On Mar 6, 2013, at 2:21 PM, Joseph Clark <joecl...@gmail.com 
> <javascript:>> wrote: 
> > 
> >> Quick question: is there an easy way to pause and unpause the 
> game/clock/scheduler with pyglet?  If now, how would you program this? 
> >> 
> >> -- 
> >> 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 <javascript:>. 
> >> To post to this group, send email to pyglet...@googlegroups.com 
> <javascript:>. 
> >> 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 pyglet-users...@googlegroups.com <javascript:>. 
> > To post to this group, send email to pyglet...@googlegroups.com 
> <javascript:>. 
> > 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 pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to