Calculate lastframe_limit only one time, as it does not change
[experiments/pygame.git] / 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
 
-    def draw(self, screen):
-        self.y += self.offset
-
         # 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
-        self.y %= lastframe_limit
+        self.y %= self.lastframe_limit
 
         screen.blit(self.texture, (self.x, self.y))