commit:edd5c795921f73545f6021dda878a80f285b3055
author:chip
committer:chip
date:Mon Nov 12 09:37:02 2007 +0000
parents:6f8815fe5a2bf5674664b36aa06407f4ac3d3709
Added FPS limiting
diff --git a/bouncetest.py b/bouncetest.py
line changes: +9/-8
index 9b36cbc..8d36490
--- a/bouncetest.py
+++ b/bouncetest.py
@@ -28,7 +28,7 @@ except IndexError:
 pygame.init()
 pygame.display.set_mode(resolution, OPENGL|DOUBLEBUF)
 #pygame.display.set_mode(resolution, DOUBLEBUF)
-pygame.display.set_caption("bouncetest: loading")
+pygame.display.set_caption("bouncetest [loading]")
 
 
 #setup the camera
@@ -47,6 +47,7 @@ class Bouncer:
 		self.sprite.color = (random.random(),random.random(),random.random(), 0.5)
 		self.sprite.position = [random.randrange(0,resolution[0]),random.randrange(0,resolution[1])]
 		self.sprite.gen_displaylist()
+		self.draw = self.sprite.draw
 
 	def update(self):
 		if self.sprite.position[0] < 0:
@@ -68,12 +69,12 @@ class Bouncer:
 		self.sprite.position[1] += self.velocity[1]
 
 bouncers = []
-for i in range(0,9001):
+for i in range(0,130):
 	h = Bouncer()
 	bouncers.append(h)
 
 pygame.display.set_caption("bouncetest")
-t = pygame.time.get_ticks()
+fpsman = pygame.time.Clock()
 n = 0
 while 1:
 	event = pygame.event.poll()
@@ -85,13 +86,13 @@ while 1:
 
 	for b in bouncers:
 		b.update()
-		b.sprite.draw()
+		b.draw()
 
 	pygame.display.flip()
-	#pygame.time.wait(10)
+	fpsman.tick(60)
 	n += 1
 	if n == 100:
-		now = pygame.time.get_ticks()
-		pygame.display.set_caption("bouncetest [%0.1f FPS]" % (100./((now-t)/1000.)))
+		fps = "%0.1f FPS" % fpsman.get_fps()
+		pygame.display.set_caption("bouncetest [%s]" % fps)
+		print fps
 		n = 0
-		t = now