On 7/18/08, simpsus_science <[EMAIL PROTECTED]> wrote:
>
>  Hallo,
>
>  in 1.0 I had to control the main loop myself, so i could check if i am
>  paused or not. Happily, this cpu thrashing is gone with 1.1. But, how
>  would I implement pause now?

For my PyWeek entry, I created a game clock (another instance of
pyglet.clock.Clock), with a custom time function that returned the
game time.  The game clock is then manually ticked by the global clock
only if the game is not paused.  In this example a fixed timestep is
used on the game clock, which is useful for collision detection.

class Game(object):
    game_time = 0
    accum_time = 0
    update_t = 1/60.

    def __init__(self):
        self.clock = pyglet.clock.Clock(time_function=lambda: self.game_time)
        pyglet.clock.schedule_interval(self.update, self.update_t)

    def update(self, dt):
        if self.paused:
            return

        # Align updates to fixed timestep
        self.accum_t += dt
        if self.accum_t > self.update_t * 3:
            self.accum_t = self.update_t
        while self.accum_t >= self.update_t:
            self.game_time += self.update_t
            self.clock.tick()
            self.accum_t -= self.update_t

Now just remember to schedule game events on the game clock, and
real-world events on the pyglet clock (usually just menu animations).

Alex.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to