【发布时间】:2019-08-18 00:48:00
【问题描述】:
我正在尝试找出创建具有多种状态的动画的最佳方法,但我似乎无法找到任何以干净方式实现我所追求的示例。
我有一个角色的精灵表,它有两种跳跃动画状态,有 6 帧角色动画基本上是从地面上跳下来。
还有另外 6 帧,角色处于“跳跃循环”中,因此角色已经离开地面,但手臂等略微移动。
当我将所有图像放入一个列表并遍历它们时,跳跃的初始部分看起来不错,因为角色离开地面然后进入跳跃循环。但是一旦帧的跳跃循环序列完成,动画就会回到半空中的开始,所以看起来角色只是从什么东西上跳下来。
我目前的功能代码如下
def animate(self):
now = pg.time.get_ticks()
# Jumping
if self.jumping:
if now - self.last_update > 18:
self.last_update = now
if self.left:
self.current_frame = (self.current_frame + 1) % len(self.jump_l)
bottom = self.rect.midbottom
self.image = self.jump_l[self.current_frame]
self.rect = self.image.get_rect()
elif self.right:
self.current_frame = (self.current_frame + 1) % len(self.jump_r)
bottom = self.rect.midbottom
self.image = self.jump_r[self.current_frame]
self.rect = self.image.get_rect()
self.rect.midbottom = bottom
动画有效,但基本上我想做的只是前 6 帧,然后循环播放最后 6 帧,直到角色落地。
【问题讨论】:
-
能否贴出完整的代码和图片来源。
标签: python animation pygame sprite-sheet