本文整理汇总了Python中sprite.Sprite.scale方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.scale方法的具体用法?Python Sprite.scale怎么用?Python Sprite.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.scale方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_sprite
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import scale [as 别名]
def load_sprite(self, file_path):
"""Calls Sprite() and checks all that it can throw"""
try:
sprite = Sprite(file_path)
sprite.scale = self.settings['scale']
sprite.source_pixels_to_points = self.settings['source-pixels-to-points']
except IOError:
self.error = "Could not open file '{0}'".format(file_path)
return None
else:
return sprite
示例2: test_sprite_scale_method
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import scale [as 别名]
def test_sprite_scale_method(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((0, 0))
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((2, 1))
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]))