当前位置: 首页>>代码示例>>Python>>正文


Python Sprite.rect方法代码示例

本文整理汇总了Python中sprite.Sprite.rect方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.rect方法的具体用法?Python Sprite.rect怎么用?Python Sprite.rect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sprite.Sprite的用法示例。


在下文中一共展示了Sprite.rect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sprite_move_method

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import rect [as 别名]
    def test_sprite_move_method(self):
        sprite1 = Sprite()
        sprite1.position = Vec2D(100, 200)
        sprite1.rect = pygame.Rect(1, 2, 50, 50)

        sprite2 = Sprite()
        sprite2.position = Vec2D(0, 0)
        sprite2.rect = pygame.Rect(-50, -10, 50, 10)

        sprite3 = Sprite()
        sprite3.position = Vec2D(0, 1)
        sprite3.rect = pygame.Rect(1, 2, 4, 4)

        sprite1.move((7, 9))
        self.assertEqual(sprite1.position, Vec2D(107, 209))
        self.assertEqual(sprite1.rect.topleft, Vec2D(8, 11))
        self.assertEqual(sprite1.rect.center, Vec2D(33, 36))
        self.assertEqual(sprite1.rect.width, 50)
        self.assertEqual(sprite1.rect.width, 50)

        sprite2.move((-100, 100))
        self.assertEqual(sprite2.position, Vec2D(-100, 100))
        self.assertEqual(sprite2.rect.topleft, Vec2D(-150, 90))
        self.assertEqual(sprite2.rect.center, Vec2D(-125, 95))
        self.assertEqual(sprite2.rect.width, 50)
        self.assertEqual(sprite2.rect.height, 10)

        sprite3.move(Vec2D(0, 0))
        self.assertEqual(sprite3.position, (0, 1))
        self.assertEqual(sprite3.rect.topleft, (1, 2))
        self.assertEqual(sprite3.rect.center, (3, 4))
        self.assertEqual(sprite3.rect.width, 4)
        self.assertEqual(sprite3.rect.height, 4)
开发者ID:gshopov,项目名称:Pyruto,代码行数:35,代码来源:test_sprite.py

示例2: test_scale_sprite

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import rect [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]))
开发者ID:gshopov,项目名称:Pyruto,代码行数:40,代码来源:test_sprite.py


注:本文中的sprite.Sprite.rect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。