本文整理汇总了Python中sprite.Sprite.images方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.images方法的具体用法?Python Sprite.images怎么用?Python Sprite.images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.images方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flip_sprite
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import images [as 别名]
def test_flip_sprite(self):
surfaces = [load_image("assets/buttons/button1.png"),
load_image("assets/buttons/button2.png")]
sprite_list = Sprite()
sprite_list.images = [item for item in surfaces]
sprite_dict = Sprite()
sprite_dict.images = {key: surfaces[key] for key in
range(len(surfaces))}
sprite_list = flip_sprite(sprite_list, 1, 0)
self.assertIsInstance(sprite_list, Sprite)
for image, rect in sprite_list.images:
index = sprite_list.images.index((image, rect))
self.assertEqual(rect, surfaces[index][1])
width, height = image.get_size()
pixel_array_base = pygame.PixelArray(surfaces[index][0])
pixel_array_flip = pygame.PixelArray(image)
for column in range(width - 1, -1, -1):
for row in range(height):
self.assertEqual(pixel_array_base[column, row],
pixel_array_flip[width - 1 - column, row])
sprite_dict = Sprite()
sprite_dict.images = {key: surfaces[key]
for key in range(len(surfaces))}
sprite_dict = flip_sprite(sprite_dict, 0, 1)
self.assertIsInstance(sprite_dict, Sprite)
for key in sprite_dict.images:
image, rect = sprite_dict.images[key]
self.assertEqual(rect, surfaces[key][1])
width, height = image.get_size()
pixel_array_base = pygame.PixelArray(surfaces[key][0])
pixel_array_flip = pygame.PixelArray(image)
for column in range(width):
for row in range(height - 1, -1, -1):
self.assertEqual(pixel_array_base[column, row],
pixel_array_flip[column,
height - 1 - row])
sprite_with_image = Sprite()
sprite_with_image.image, sprite_with_image.rect = surfaces[0]
sprite_with_image = flip_sprite(sprite_with_image, 1, 1)
self.assertIsInstance(sprite_with_image, Sprite)
self.assertEqual(sprite_with_image.rect, surfaces[0][1])
width, height = sprite_with_image.image.get_size()
pixel_array_base = pygame.PixelArray(surfaces[0][0])
pixel_array_flip = pygame.PixelArray(sprite_with_image.image)
for column in range(width - 1, -1, -1):
for row in range(height - 1, -1, -1):
self.assertEqual(pixel_array_base[column, row],
pixel_array_flip[width - 1 - column,
height - 1 - row])
示例2: test_scale_sprite
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import images [as 别名]
def test_scale_sprite(self):
surfaces = [pygame.Surface((0, 0)), pygame.Surface((0, 298)),
pygame.Surface((10, 0)), pygame.Surface((13, 7))]
sprite_list = Sprite()
sprite_list.image = pygame.Surface((1000, 1000))
sprite_list.rect = sprite_list.image.get_rect()
sprite_list.rect.topleft = (7, 17)
sprite_list.images = [(surface, surface.get_rect())
for surface in surfaces]
sprite_dict = Sprite()
sprite_dict.image = pygame.Surface((23, 29))
sprite_dict.rect = sprite_dict.image.get_rect()
sprite_dict.rect.topleft = (0, 0)
sprite_dict.images = {key: (surfaces[key], surfaces[key].get_rect())
for key in range(len(surfaces))}
sprite_list = scale_sprite(sprite_list, (0, 0))
self.assertIsInstance(sprite_list, Sprite)
self.assertIsInstance(sprite_list, Sprite)
self.assertEqual(sprite_list.image.get_size(), (0, 0))
self.assertEqual(sprite_list.rect, pygame.Rect(7, 17, 0, 0))
for image, rect in sprite_list.images:
self.assertEqual(image.get_size(), (0, 0))
self.assertEqual(rect, pygame.Rect(0, 0, 0, 0))
sprite_dict = scale_sprite(sprite_dict, (2, 1))
self.assertIsInstance(sprite_dict, Sprite)
self.assertIsInstance(sprite_dict, Sprite)
self.assertEqual(sprite_dict.image.get_size(), (23 * 2, 29))
self.assertEqual(sprite_dict.rect, pygame.Rect(0, 0, 23 * 2, 29))
for key, tuple in sprite_dict.images.items():
self.assertEqual(tuple[0].get_size(),
Vec2D(surfaces[key].get_size()) * Vec2D(2, 1))
self.assertEqual(tuple[1], pygame.Rect(0, 0,
surfaces[key].get_size()[0] * 2,
surfaces[key].get_size()[1]))