# HG changeset patch # User Jeremy Thurgood # Date 1302366239 -7200 # Node ID 6a8f98335a53a97a7f3d1a88edbfb187de9907d8 # Parent 1e2eb4df061ffbc495e5299824de4a38eab27884 Crop background image if necessary. diff -r 1e2eb4df061f -r 6a8f98335a53 skaapsteker/level.py --- a/skaapsteker/level.py Sat Apr 09 18:22:27 2011 +0200 +++ b/skaapsteker/level.py Sat Apr 09 18:23:59 2011 +0200 @@ -4,7 +4,7 @@ from pygame.sprite import LayeredUpdates from . import data -from .constants import Layers +from .constants import SCREEN, Layers from .sprites.base import TILE_SIZE, find_sprite, Geography from .widgets.text import Text @@ -63,8 +63,8 @@ self.level_data = json.loads(data.load('levels/' + leveldef + '.json').read()) self.sprites = LayeredUpdates() self._soundsystem = soundsystem + self.build_tiles() self.build_backgrounds() - self.build_tiles() self.setup_enemies() self.setup_doorways() self._background_music = None @@ -74,8 +74,21 @@ def build_backgrounds(self): self.backgrounds = [] - for background in self.level_data['backgrounds']: - self.backgrounds.append(data.load_image('backgrounds/' + background)) + for i, background in enumerate(self.level_data['backgrounds']): + image = data.load_image('backgrounds/' + background) + if i == 0: + print "background:", background, image.get_rect() + print "pixel_size:", self.pixel_size + clip_rect = Rect((0, 0), (int(self.pixel_size[0] * 0.75), int(self.pixel_size[1] * 0.75))) + print "initial:", clip_rect + clip_rect = clip_rect.clip(image.get_rect()) + print "clipped to image:", clip_rect + clip_rect = clip_rect.union(Rect((0, 0), SCREEN)) + print "unioned to screen:", clip_rect + clip_rect.midbottom = image.get_rect().midbottom + print "offset:", clip_rect + image = image.subsurface(clip_rect) + self.backgrounds.append(image) def enter(self): if self._background_music: