说明:

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. 消息中间件——activeMQ

    Activemq使用教程 解压activmq进入bin\win64 启动activemq.bat 启动成功 浏览器访问http://127.0.0.1:8161 创建maven工程 在pom.xml中 ...

  2. uniGUI中Cookies使用中文汉字的方法(使用EncodeString函数编码)

    uniGUI中Cookies使用中文汉字的方法(使用EncodeString函数编码)   在目前的UniGUI(ver:0.88)中使用UniApplication.Cookies.SetCooki ...

  3. 微服务日志之Spring Boot Kafka实现日志收集

    前言 承接上文( 微服务日志之.NET Core使用NLog通过Kafka实现日志收集 https://www.cnblogs.com/maxzhang1985/p/9522017.html ).NE ...

  4. localStorage 存满了怎么办?

    先来几道面试题 1.a.meituan.com 和 b.meituan.com 这两个域能够共享同一个 localStorage 吗? 2.在 webview 中打开一个页面:i.meituan.co ...

  5. HoloLens开发手记 - 使用Visual Studio Using Visual Studio

    不论你是否使用DirectX或Unity来开发全息应用,你都会使用Visual Studio 2015来进行调试和部署应用.在本部分,你将会学习以下内容: 如何通过Visual Studio将你的应用 ...

  6. 实例分析JAVA CLASS的文件结构

    今天把之前在Evernote中的笔记重新整理了一下,发上来供对java class 文件结构的有兴趣的同学参考一下. 学习Java的朋友应该都知道Java从刚开始的时候就打着平台无关性的旗号,说“一次 ...

  7. HDU 5113--Black And White(搜索+剪枝)

    题目链接 Problem Description In mathematics, the four color theorem, or the four color map theorem, stat ...

  8. ZolltyMVC配置-说明文档

    目前XML里支持的一级元素如下: <!-- 配置 -->     <xsd:element ref="mvc"/>     <xsd:element ...

  9. Oracle.ManagedDataAccess 提示ORA-01017 错误【解决方案】

    Oracle.ManagedDataAccess 提示ORA-01017 错误[解决方案] Oracle.ManagedDataAccess 提示ORA-01017 错误[解决方案] [HKEY_LO ...

  10. 关于微信JS SDK接口wx.previewImage预览接口的使用

    然后后之前的项目,突然往微信上迁移了,一些微信的接口没怎么用过,比较陌生,这次的功能是想调用微信的接口,实现图片放大的功能, 就找到官方文档:http://qydev.weixin.qq.com/wi ...