说明:

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)

pygame编组(精灵组)Group中的常用方法介绍的更多相关文章

  1. 5.pygame快速入门-精灵和精灵组

    在之前案例中,图像加载.位置变化.绘制图像都需要编写代码分别处理 pygame提供了两个类简化开发步骤 pygame.sprite.Sprite #精灵,存储图像数据image和位置rect的对象 p ...

  2. 8、Situation-Dependent Combination of Long-Term and Session-Based Preferences in Group Recommendations: An Experimental Analysis ----组推荐中基于长期和会话偏好的情景依赖组合

    一.摘要: 背景:会话组推荐系统的一个主要挑战是如何适当地利用群组成员之间的交互引起用户偏好,这可能会偏离用户的长期偏好.长期偏好和群组诱导的偏好之间的相对重要性应该根据具体的群组设置而变化. 本文: ...

  3. java中正则表达式常用方法

    一.匹配 String  matches()方法.用规则匹配整个字符串,只要有一处不符合规则,就匹配结束,返回false. 举例: public static void checkQQ(){ Stri ...

  4. Java中的常用方法

    Java中的常用方法 第一章 字符串 1.获取字符串的长度:length() 2.判断字符串的前缀或后缀与已知字符串是否相同    前缀 startsWith(String s).后缀 endsWit ...

  5. Java实战之02Hibernate-03Session中的常用方法

    九.Session中的常用方法 1.save方法 都是临时态————>持久态 2.persist方法 作用: 持久化临时态对象. 与save方法的区别: 开始了事务:persist和save没有 ...

  6. javascript中数组常用方法总结

    原文:javascript中数组常用方法总结 在javascript的基础编程中,数组是我们最常遇到的,那么数组的一些常用方法也是我们必须要掌握的,下面我们总结一下数组中常用的方法. toString ...

  7. python中os常用方法

    python中OS常用方法 Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问 ...

  8. Java多线程中的常用方法

    本文将带你讲诉Java多线程中的常用方法   Java多线程中的常用方法有如下几个 start,run,sleep,wait,notify,notifyAll,join,isAlive,current ...

  9. JavaScript中Math常用方法

    title: JavaScript中Math常用方法 toc: false date: 2018-10-13 12:19:31 Math.E --2.718281828459045,算数常量e Mat ...

随机推荐

  1. CASUAL_NCT

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...

  2. [CocoaPods]使用Trunk进行设置

    CocoaPods Trunk CocoaPods Trunk是一种身份验证和CocoaPods API服务.要将新的或更新的库发布到CocoaPods以进行公开发布,您需要在Trunk中注册并在当前 ...

  3. Ubuntu 16.04 安装 arm-linux-gcc 交叉编译工具

    工作需要,最近在编译linux嵌入式内核时,需要安装arm-linux-gcc交叉编译,实际上,安装这个交叉编译器的难度没啥.不过,这里有些问题还是值得我去思考和记录下来的. 这个系统的上的编译器用的 ...

  4. LeetCode:114_Flatten Binary Tree to Linked List | 将一棵二叉树变成链表的形式 | Medium

    要求:Given a binary tree, flatten it to a linked list in-place.将二叉树转化为平坦序列的树.比如: 结题思路: 该题有个提示,转化后的树的序列 ...

  5. Liferay7 BPM门户开发之4: Activiti事件处理和监听Event handlers

    事件机制从Activiti 5.15开始引入,这非常棒,他可以让你实现委托. 可以通过配置添加事件监听器,也可以通过Runtime API加入注册事件. 所有的事件参数子类型都来自org.activi ...

  6. Servlet-session简介及使用场景

  7. Spring 异常处理三种方式 @ExceptionHandler

    异常处理方式一. @ExceptionHandler 异常处理方式二. 实现HandlerExceptionResolver接口 异常处理方式三. @ControllerAdvice+@Excepti ...

  8. 服务器运维 -- windows系统更换System32下文件后 重启无法进入桌面

    场景描述: windows系统更换System32下文件后 重启无法进入桌面 情况1,原替换文件有备份     解决建议: 准备好该文件 情况2,原备份文件没有备份  解决建议:从相同版本的服务器上边 ...

  9. logrotate实现Mysql慢日志分割

    MySQL慢日志? MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long_query_time值的SQL,则会被记录到慢查询 ...

  10. Jenkins配置AD域认证

    Jenkins配置AD域认证 #检测域控地址ping youad.com指向的IP #如果不是实际域控ip地址,则修改hosts vi /etc/hosts #192.168.100.100替换为实际 ...