zoukankan      html  css  js  c++  java
  • pygame编组(精灵组)Group中的常用方法介绍

    说明:

    1.以下所用的Group均为Group类的对象实例

    2.Group类是对AbstractGroup类的继承

    sprite.py文档中描述如下:

    class Group(AbstractGroup):
        """container class for many Sprites
    
        pygame.sprite.Group(*sprites): return Group
    
        A simple container for Sprite objects. This class can be subclassed to
        create containers with more specific behaviors. The constructor takes any
        number of Sprite arguments to add to the Group. The group supports the
        following standard Python operations:
    
            in      test if a Sprite is contained
            len     the number of Sprites contained
            bool    test if any Sprites are contained
            iter    iterate through all the Sprites
    
        The Sprites in the Group are not ordered, so the Sprites are drawn and
        iterated over in no particular order.
    
        """
        def __init__(self, *sprites):
            AbstractGroup.__init__(self)
            self.add(*sprites)
    

    方法一:Group.draw(surface)

    说明:对精灵组中的每一个精灵依次调用surface.blit(),依次将精灵组中的精灵绘制在surface上

    AbstractGroup类中对其的定义:

        def draw(self, surface):
            """draw all sprites onto the surface
    
            Group.draw(surface): return None
    
            Draws all of the member sprites onto the given surface.
    
            """
            sprites = self.sprites()
            surface_blit = surface.blit
            for spr in sprites:
                self.spritedict[spr] = surface_blit(spr.image, spr.rect)
            self.lostsprites = []

    方法二:Group.update()

    说明:对精灵组中的每一个精灵依次调用update()方法,并且update()方法需要自己在自己定义的精灵类中去实现

    AbstractGroup类中对其的定义:

        def update(self, *args):
            """call the update method of every member sprite
    
            Group.update(*args): return None
    
            Calls the update method of every member sprite. All arguments that
            were passed to this method are passed to the Sprite update function.
    
            """
            for s in self.sprites():
                s.update(*args)
    蒹葭苍苍,白露为霜; 所谓伊人,在水一方。
  • 相关阅读:
    如何重新加载 Spring Boot 上的更改,而无需重新启动服务器?
    FileUpload拦截器
    aspnet网页刷新
    查看SQL表的详细信息
    学习GDI+ (1)
    设计模式简单工厂模式
    对数据库表操作,统一的方法。
    随机产生300道四则运算
    略谈从计算机专业,再到软件构建的初识
    #在android studio中维护日程管理系统
  • 原文地址:https://www.cnblogs.com/huwt/p/10333500.html
Copyright © 2011-2022 走看看