1 """A timer for games with set-rate FPS.
9 # The game time when one of the clock parameters was last changed
11 # The real time corresponding to the last game time
13 # The game time when 'tick' was last called
16 # Whether the timer is paused or not
18 # When this clock was created
20 # The speed which this clock moves at relative to the real clock
24 #self.startTime = time.time()
27 self.lastRealTime = time.time()
28 self.startTime = time.time()
30 # Set the rate at which this clock ticks relative to the real clock
31 def set_speed(self, n):
33 self.lastGameTime = self.get_time()
34 self.lastRealTime = time.time()
40 self.lastGameTime = self.get_time()
41 self.lastRealTime = time.time()
48 self.lastRealTime = time.time()
50 def tick(self, fps=0):
52 dt = tm - self.lastTickTime
56 pygame.time.wait(int((minTime-dt)*1000))
58 self.lastTickTime = tm
61 # Returns the amount of 'game time' that has passed since creating
62 # the clock (paused time does not count).
65 return self.lastGameTime
66 return self.speed*(time.time()-self.lastRealTime) + self.lastGameTime
68 def get_real_time(self):
69 return (time.time()-self.startTime)
73 """A timer for games with set-rate FPS."""
75 def __init__(self,fps):
77 self.tick = self._blank
80 self.nt = pygame.time.get_ticks()
87 """Wait correct amount of time each frame. Call this once per frame."""
88 self.ct = pygame.time.get_ticks()
90 pygame.time.wait(self.nt-self.ct)
93 self.nt = pygame.time.get_ticks()+self.wait
97 """A timer replacement that returns out FPS once a second.
100 fps -- always set to the current FPS
105 self.st = pygame.time.get_ticks()
109 """ Call this once per frame."""
112 self.ct = pygame.time.get_ticks()
113 if (self.ct - self.st) >= 1000:
114 r = self.fps = self.frames
115 #print "%s: %d fps"%(self.__class__.__name__,self.fps)
118 pygame.time.wait(0) #NOTE: not sure why, but you gotta call this now and again