Message from discussion
Pausing in 1.1
MIME-Version: 1.0
Received: by 10.100.152.19 with SMTP id z19mr17506and.27.1216401737508; Fri,
18 Jul 2008 10:22:17 -0700 (PDT)
Date: Fri, 18 Jul 2008 10:22:17 -0700 (PDT)
In-Reply-To: <7b175ae90807180930q4c1b165am3ac022d53d37aa01@mail.gmail.com>
X-IP: 12.127.238.42
References: <a595a3d5-9b7e-4453-9526-e69d7f81f7bb@p25g2000hsf.googlegroups.com>
<200807180807.01380.r1chardj0n3s@gmail.com> <3ff8d5b3-54cd-493a-ad47-717098e0c278@79g2000hsk.googlegroups.com>
<249b6faa0807171730k7a3edfcal743c64b339e1ddd8@mail.gmail.com>
<f13b3c45-758e-42ef-af15-f385cd08511e@y21g2000hsf.googlegroups.com>
<7b175ae90807180930q4c1b165am3ac022d53d37aa01@mail.gmail.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
rv:1.9) Gecko/2008061004 Firefox/3.0,gzip(gfe),gzip(gfe)
Message-ID: <1ac05fc9-4f1c-41a1-b62a-f47f7493f977@c65g2000hsa.googlegroups.com>
Subject: Re: Pausing in 1.1
From: "dior...@gmail.com" <dior...@gmail.com>
To: pyglet-users <pyglet-users@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I haven't written much Python in a couple of months, and I didn't test
the code below at all except to check that it compiles, but it's a
start. Feel free to steal, tweak, and correct. If I have Python's
module behavior straight, you should be able to stick this in
gametime.py, import it, and then just call gametime.pause() and
gametime.unpause().
import pyglet.clock, time
pause_start = 0
total_pause_time = 0
paused = False
def game_time():
if paused:
return pause_start - total_pause_time
else:
return time.time() - total_pause_time
def pause():
if not paused:
paused = True
pause_start = time.time()
def unpause():
if paused:
paused = False
total_pause_time += time.time() - pause_start