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


Python sprite.Sprite方法代码示例

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


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

示例1: setUp

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def setUp(self):
        self.ag = sprite.AbstractGroup()
        self.ag2 = sprite.AbstractGroup()
        self.s1 = sprite.Sprite(self.ag)
        self.s2 = sprite.Sprite(self.ag2)
        self.s3 = sprite.Sprite(self.ag2)

        self.s1.image = pygame.Surface((50,10), pygame.SRCALPHA, 32)
        self.s2.image = pygame.Surface((10,10), pygame.SRCALPHA, 32)
        self.s3.image = pygame.Surface((10,10), pygame.SRCALPHA, 32)

        self.s1.rect = self.s1.image.get_rect()
        self.s2.rect = self.s2.image.get_rect()
        self.s3.rect = self.s3.image.get_rect()
        self.s2.rect.move_ip(40, 0)
        self.s3.rect.move_ip(100, 100) 
开发者ID:it2school,项目名称:Projects,代码行数:18,代码来源:sprite_test.py

示例2: test_update

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def test_update(self):

        class test_sprite(pygame.sprite.Sprite):
            sink = []
            def __init__(self, *groups):
                pygame.sprite.Sprite.__init__(self, *groups)
            def update(self, *args):
                self.sink += args

        s = test_sprite(self.ag)
        self.ag.update(1, 2, 3)

        self.assertEqual(test_sprite.sink, [1, 2, 3])


################################################################################

# A base class to share tests between similar classes 
开发者ID:it2school,项目名称:Projects,代码行数:20,代码来源:sprite_test.py

示例3: test_has

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def test_has( self ):
        " See if AbstractGroup.has() works as expected. "

        ag = sprite.AbstractGroup()
        ag2 = sprite.AbstractGroup()
        s1 = sprite.Sprite(ag)
        s2 = sprite.Sprite(ag)
        s3 = sprite.Sprite(ag2)
        s4 = sprite.Sprite(ag2)
    
        self.assertEqual(True, s1 in ag )
    
        self.assertEqual(True, ag.has(s1) )
    
        self.assertEqual(True, ag.has([s1, s2]) )
    
        # see if one of them not being in there.
        self.assertNotEqual(True, ag.has([s1, s2, s3]) )
    
        # see if a second AbstractGroup works.
        self.assertEqual(True, ag2.has(s3) ) 
开发者ID:Plottel,项目名称:AIFun,代码行数:23,代码来源:sprite_test.py

示例4: todo_test_update

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def todo_test_update(self):

        # __doc__ (as of 2008-08-02) for pygame.sprite.AbstractGroup.update:

          # update(*args)
          # call update for all member sprites
          # 
          # calls the update method for all sprites in the group.
          # Passes all arguments on to the Sprite update function.

        self.fail()


################################################################################

# A base class to share tests between similar classes 
开发者ID:Plottel,项目名称:AIFun,代码行数:18,代码来源:sprite_test.py

示例5: test_alive

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def test_alive(self):
        self.assert_(
            not self.sprite.alive(),
            "Sprite should not be alive if in no groups"
        )

        self.sprite.add(self.groups)
        self.assert_(self.sprite.alive()) 
开发者ID:it2school,项目名称:Projects,代码行数:10,代码来源:sprite_test.py

示例6: test_memoryleak_bug

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def test_memoryleak_bug(self):
        # For memoryleak bug posted to mailing list by Tobias Steinrücken on 16/11/10.
        # Fixed in revision 2953.
        
        import weakref
        import gc
        
        class MySprite(sprite.Sprite):
            def __init__(self, *args, **kwargs):
                sprite.Sprite.__init__(self, *args, **kwargs)
                self.image = pygame.Surface( (2, 4), 0, 24 )
                self.rect = self.image.get_rect()
                
        g = sprite.GroupSingle()
        screen = pygame.Surface((4, 8), 0, 24)
        s = MySprite()
        r = weakref.ref(s)
        g.sprite = s
        del s
        gc.collect()
        self.assert_(r() is not None)
        g.update()
        g.draw(screen)
        g.sprite = MySprite()
        gc.collect()
        self.assert_(r() is None)
        
################################################################################ 
开发者ID:it2school,项目名称:Projects,代码行数:30,代码来源:sprite_test.py

示例7: __init__

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def __init__(self, settings, screen, image):
        """Initialize the block, not much to do other than save the params"""
        super().__init__()
        self.settings = settings
        self.screen = screen
        self.image = image
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        self.dying = False

    # 'draw' is required by pygame.Sprite.Group for drawing in batches 
开发者ID:manixaist,项目名称:pyclimber,代码行数:13,代码来源:block.py

示例8: __init__

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def __init__(self, settings, screen, images):
        """Init the Animated Sprite logic"""
        super().__init__()
        # cache these objects
        self.settings = settings
        self.screen = screen
        self.images = images
        self.screen_rect = screen.get_rect()

        # All images are the same size, so set the rect to the first one
        self.rect = images[0].get_rect()

        # Initially not moving and not falling
        self.dx = 0.0
        self.dy = 0.0
        self.falling = False
        self.falling_frames = 0
        self.dying = False

        # These are designed to be overridden by the parent class
        self.animations = {}
        self.current_animation = None
        self.facing_left = False
        self.margin_left = 0
        self.margin_right = 0
        self.margin_top = 0
        self.margin_bottom = 0

        # Overrides
        self.bound_by_the_laws_of_physics = True
        self.bound_by_map = True

        # Collision check callback (optional)
        self.collision_check = None 
开发者ID:manixaist,项目名称:pyclimber,代码行数:36,代码来源:animated_sprite.py

示例9: update

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def update(self, tile_map, collision_check_group=None):
        """Updates the sprite's basic position, more detailed collision is left to the derived class"""
        if self.bound_by_the_laws_of_physics:
            self.apply_physics(tile_map)

        if self.bound_by_map:
            self.basic_bounds_containment(tile_map)
        
         # Sprite collision
        if collision_check_group:
            intersected_sprites = pygame.sprite.spritecollide(self, collision_check_group, False, self.collision_check)
            # This is required by the implementing class, this function will allow the sub-types of
            # sprite objects to handle the collisions differently - just like the self.collision_check
            # function allows them to alter the actual collision detection (e.g. based on transparent margins)
            self.handle_collision(intersected_sprites, collision_check_group) 
开发者ID:manixaist,项目名称:pyclimber,代码行数:17,代码来源:animated_sprite.py

示例10: todo_test_spritecollideany

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def todo_test_spritecollideany(self):

        # __doc__ (as of 2008-08-02) for pygame.sprite.spritecollideany:

          # pygame.sprite.spritecollideany(sprite, group) -> sprite
          # finds any sprites that collide
          # 
          # given a sprite and a group of sprites, this will
          # return return any single sprite that collides with
          # with the given sprite. If there are no collisions
          # this returns None.
          # 
          # if you don't need all the features of the
          # spritecollide function, this function will be a
          # bit quicker.
          # 
          # collided is a callback function used to calculate if
          # two sprites are colliding. it should take two sprites
          # as values, and return a bool value indicating if
          # they are colliding. if collided is not passed, all
          # sprites must have a "rect" value, which is a
          # rectangle of the sprite area, which will be used
          # to calculate the collision.
          # 
          # Test if the given Sprite intersects with any Sprites in a Group.
          # Intersection is determined by comparing of the Sprite.rect attribute
          # of each Sprite.
          # 
          # This collision test can be faster than pygame.sprite.spritecollide()
          # since it has less work to do.

        self.fail() 
开发者ID:Plottel,项目名称:AIFun,代码行数:34,代码来源:sprite_test.py

示例11: todo_test_groupcollide

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def todo_test_groupcollide(self):

        # __doc__ (as of 2008-08-02) for pygame.sprite.groupcollide:

          # pygame.sprite.groupcollide(groupa, groupb, dokilla, dokillb) -> dict
          # collision detection between group and group
          # 
          # given two groups, this will find the intersections
          # between all sprites in each group. it returns a
          # dictionary of all sprites in the first group that
          # collide. the value for each item in the dictionary
          # is a list of the sprites in the second group it
          # collides with. the two dokill arguments control if
          # the sprites from either group will be automatically
          # removed from all groups.
          # collided is a callback function used to calculate if
          # two sprites are colliding. it should take two sprites
          # as values, and return a bool value indicating if
          # they are colliding. if collided is not passed, all
          # sprites must have a "rect" value, which is a
          # rectangle of the sprite area, which will be used
          # to calculate the collision.
          # 
          # This will find intersections between all the Sprites in two groups.
          # Intersection is determined by comparing the Sprite.rect attribute of
          # each Sprite.
          # 
          # Every Sprite inside group1 is added to the return dictionary. The
          # value for each item is the list of Sprites in group2 that intersect.
          # 
          # If either dokill argument is True, the intersecting Sprites will be
          # removed from their respective Group.

        self.fail() 
开发者ID:Plottel,项目名称:AIFun,代码行数:36,代码来源:sprite_test.py

示例12: todo_test_add_internal

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def todo_test_add_internal(self):

        # __doc__ (as of 2008-08-02) for pygame.sprite.Sprite.add_internal:

        self.fail() 
开发者ID:Plottel,项目名称:AIFun,代码行数:7,代码来源:sprite_test.py

示例13: todo_test_remove_internal

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def todo_test_remove_internal(self):

        # __doc__ (as of 2008-08-02) for pygame.sprite.Sprite.remove_internal:

        self.fail() 
开发者ID:Plottel,项目名称:AIFun,代码行数:7,代码来源:sprite_test.py

示例14: test___init____added_to_groups_passed

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Sprite [as 别名]
def test___init____added_to_groups_passed(self):
        self.sprite = self.Sprite(self.groups)

        self.assert_(unordered_equality(
            self.sprite.groups(),
            self.groups
        )) 
开发者ID:Plottel,项目名称:AIFun,代码行数:9,代码来源:sprite_test.py


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