Mercurial > skaapsteker
changeset 428:6a8f98335a53
Crop background image if necessary.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 18:23:59 +0200 |
parents | 1e2eb4df061f |
children | 8b047e74dfd1 |
files | skaapsteker/level.py |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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: