From 11c63f1f7ca3cd109caec1b90d2205ddae5fe2ce Mon Sep 17 00:00:00 2001 From: Calvin Spealman Date: Sun, 17 May 2020 17:17:10 -0400 Subject: [PATCH] Support Sprite.rect property, a 4-tuple controlling whthe src-rect to render from the texture. --- ppb/systems/renderer.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ppb/systems/renderer.py b/ppb/systems/renderer.py index 3a2bcec3..61891787 100644 --- a/ppb/systems/renderer.py +++ b/ppb/systems/renderer.py @@ -255,13 +255,19 @@ def compute_rectangles(self, texture, game_object, camera): src_rect = SDL_Rect(x=0, y=0, w=img_w, h=img_h) - if hasattr(game_object, 'width'): - obj_w = game_object.width - obj_h = game_object.height + if hasattr(game_object, 'rect'): + rect = game_object.rect + src_rect = SDL_Rect(*rect) + win_w, win_h = self.target_resolution(rect[2], rect[3], game_object.size, game_object.size, camera.pixel_ratio) + else: - obj_w, obj_h = game_object.size + if hasattr(game_object, 'width'): + obj_w = game_object.width + obj_h = game_object.height + else: + obj_w, obj_h = game_object.size - win_w, win_h = self.target_resolution(img_w.value, img_h.value, obj_w, obj_h, camera.pixel_ratio) + win_w, win_h = self.target_resolution(img_w.value, img_h.value, obj_w, obj_h, camera.pixel_ratio) center = camera.translate_point_to_screen(game_object.position) dest_rect = SDL_Rect(