Calculate lastframe_limit only one time, as it does not change
authorAntonio Ospite <ospite@studenti.unina.it>
Tue, 19 Mar 2013 10:30:59 +0000 (11:30 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Tue, 19 Mar 2013 10:32:32 +0000 (11:32 +0100)
pygame-vertical-scrolling-map.py

index 132b44a..75227e1 100755 (executable)
@@ -50,15 +50,15 @@ class VerticalScrollingMap(pygame.Surface):
         # Center along X
         self.x = (self.viewport_width - self.texture_widht) / 2.0
 
         # Center along X
         self.x = (self.viewport_width - self.texture_widht) / 2.0
 
-    def draw(self, screen):
-        self.y += self.offset
-
         # NOTE, we assume that the texture has at least twice the height of the
         # viewport
         # NOTE, we assume that the texture has at least twice the height of the
         # viewport
-        lastframe_limit = -(self.texture_height - self.viewport_height)
+        self.lastframe_limit = -(self.texture_height - self.viewport_height)
+
+    def draw(self, screen):
+        self.y += self.offset
 
         # Wrap around to cycle seamlessly
 
         # Wrap around to cycle seamlessly
-        self.y %= lastframe_limit
+        self.y %= self.lastframe_limit
 
         screen.blit(self.texture, (self.x, self.y))
 
 
         screen.blit(self.texture, (self.x, self.y))