def test_scroll(self):
# Create surface to render to
output_surface = pygame.surface.Surface((1, 1))
# Create fixtures
red_surface = pygame.surface.Surface((1, 1))
blue_surface = pygame.surface.Surface((1, 1))
red_surface.fill((255, 0, 0))
blue_surface.fill((0, 255, 0))
# Create the camera and blit colors to it
camera = Camera((2, 1), (1, 1), (1, 1))
camera.source_surface.blit(red_surface, (0, 0))
camera.source_surface.blit(blue_surface, (1, 0))
camera.update_state("so many of these")
# We should be at (0, 0) so blitting should get us a red pixel
output_surface.blit(camera, (0, 0))
assert(compare_surfaces(red_surface, output_surface))
# Scroll one pixel to the left, and we should get a blue pixel
# when blitting
focal_rect = pygame.Rect((1, 0), (1, 1))
camera.scroll_to(focal_rect) # updates for us
camera.update_state("just a lot")
output_surface.blit(camera, (0, 0))
assert(compare_surfaces(blue_surface, output_surface))
# FIXME: This is messy!
评论列表
文章目录