admin 管理员组文章数量: 1086866
精灵组
定义一个游戏的精灵类
class Game(pygame.sprite.Sprite):
初始化方法:
图片的路径,移动速度
def __init__(self,image,speed)
记录尺寸:
self.rect=self.image.get_rect()
记录速度:
self.speed=speed
重写update父类方法:
def update(self,*args)
精灵组:
一个精灵组可以包含多个精灵对象
调用精灵组对象的方法 update()
绘制:group.draw()
设置帧 clock=pygame.time.Clock()
pygame.sprite.Sprite运用代码:
class Snowman(pygame.sprite.Sprite):def __init__(self,image,location,speed):''':param image: 图片的路径:param location: 列表类型的属性,[x横轴坐标,y纵轴的坐标]:param speed: 列表的类型,[横轴的速度,纵轴的速度]'''pygame.sprite.Sprite.__init__(self)self.image=pygame.image.load(image)self.rect=self.image.get_rect()# self.rect.center=location#设置图像的初始位置self.rect.left,self.rect.top=locationself.speed=speed
本文标签: 精灵组
版权声明:本文标题:精灵组 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1688024450a170108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论