说明:

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. 安装VS2017后打开项目提示 asp.net 4.0尚未web服务器注册

    Visual Studio 2017 出来了,手痒安装完成后打开原来的项目缺提示,asp.net 4.0尚未web服务器注册.郁闷了… 按照提示的方法,如何:将 ASP.NET Web 应用程序升级到 ...

  2. phpMyAdmin 4.7.x CSRF 漏洞利用

    作者:Ambulong phpMyAdmin是个知名MySQL/MariaDB在线管理工具,phpMyAdmin团队在4.7.7版本中修复了一个危害严重的CSRF漏洞(PMASA-2017-9),攻击 ...

  3. Android Studio向项目中导入jar包的方法

    第一步: 切换到"Project"视图,找到app --> libs目录 第二步: 将需要导入的jar包粘贴到libs目录中,此时还不能看到jar包中的内容 第三步: 右键点 ...

  4. java调用高德地图api实现通过ip定位访问者的城市

    所需东西:高德地图的key 注意:这个key是 web服务的key  和js的key不是一个key(若没有则自行创建,创建教程在文末) 高德地图的api文档:https://lbs.amap.com/ ...

  5. app测试环境搭建(python)

    app测试环境的搭建大致如下几个: 1.appium安装 appium-server或者使用appium-desktop都可以,前者已经不再更新 下载地址:appium.io 2.Android SD ...

  6. C# DataGridView下DataGridViewComboBoxColumn二级联动

    效果: 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...

  7. .Net RPC框架Thrift的用法

      关于Thrift 下面是来自百度百科关于Thrift的介绍: thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和引擎,以构建在 C++, Java, Go ...

  8. java使用google开源工具实现图片压缩

    前言 作为靠谱的java服务端程序员,图片这个事情一直是个头疼的事情. 现在很多网站上,都有上传图片这个功能,而图片对于现在的很多手机来说,拍摄出来的都是高清图片,分辨率也是相当的高,当然占用的存储空 ...

  9. Django | Cookie 中文编码的问题

    在Django中,向cookie写入中文字符后会报错:如向cookie中保存用户名,当用户名存在中文字符时: Traceback (most recent call last): File , in ...

  10. 详解C#的协变和逆变

    一.使用协变(Covariance)和逆变(Contravariance )能够实现数组之间.委托实例和方法之间.泛型委托实例之间.泛型接口的变量和泛型类型的对象之间.泛型接口的变量之间的隐式转换:使 ...