Limit frame rate
authorStefano Rivera <stefano@rivera.za.net>
Sun, 11 May 2014 15:59:51 +0000 (17:59 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sun, 11 May 2014 15:59:51 +0000 (17:59 +0200)
naja/engine.py

index 94ddeab24a055e9134e1c51e7fef68f2a877dd58..1c6b70ac8a7917871edae10512acfc90e11b80d2 100644 (file)
@@ -1,6 +1,7 @@
 import pygame
 import pygame.locals as pgl
 
+from naja.constants import FPS
 from naja.events import SceneChangeEvent, QuitGameEvent
 
 
@@ -10,6 +11,7 @@ class Engine(object):
         self._scene = scene
 
     def run(self):
+        clock = pygame.time.Clock()
         while True:
             for ev in pygame.event.get():
                 if ev.type == pgl.QUIT or QuitGameEvent.matches(ev):
@@ -21,6 +23,7 @@ class Engine(object):
                     self._scene.handle_event(ev)
             self._scene.render(self._surface)
             pygame.display.flip()
+            clock.tick(FPS)
 
     def change_scene(self, scene):
         self._scene.exit()