Changeset 111:601d2a500e4a


Ignore:
Timestamp:
Apr 4, 2011, 7:37:31 PM (9 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
rebase_source:
6dee5272cd15f687938dc5147752b5d1b7a1986b
Message:

Hook up scrolling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r106 r111  
    2020        self._level = level.Level(leveldef, self._player)
    2121        self._level_surface = self._level.get_surface()
    22         self._pos = (0, 0)
     22        self._clip_rect = None
    2323        self._world = physics.World()
    2424        self.frozen = False
     
    7272
    7373    def draw(self, screen_surface):
     74        if self._clip_rect is None:
     75            self._clip_rect = pygame.Rect((0, 0), screen_surface.get_size())
     76
    7477        self._world.update()
     78        self._update_clip_rect()
    7579
    76         clip_rect = pygame.Rect(self._pos, screen_surface.get_size())
    77         self._level_surface.set_clip(clip_rect)
    78 
     80        self._level_surface.set_clip(self._clip_rect)
    7981        self._level.draw(self._level_surface)
    8082        self._world.draw(self._level_surface)
    8183
    82         screen_surface.blit(self._level_surface, (0, 0), clip_rect)
     84        screen_surface.blit(self._level_surface, (0, 0), self._clip_rect)
     85
     86    def _update_clip_rect(self):
     87        cr = self._clip_rect
     88        lr = self._level_surface.get_rect()
     89        cr.center = self._player.rect.center
     90        cr.move_ip(-min(cr.left - lr.left, 0), -min(cr.top - lr.top, 0))
     91        cr.move_ip(min(lr.right - cr.right, 0), min(lr.bottom - cr.bottom, 0))
     92        print cr
    8393
    8494    def dispatch(self, ev):
Note: See TracChangeset for help on using the changeset viewer.