如何解决如何根据演员在 Cocos2d Python 中面对的方向更改我的精灵图像?
我是 Cocos2d 的新手,正在研究如何使用 pyglet ImageGrid 和 Animation 方法来创建精灵动画。我已经成功地将正确的切片分配给我的僵尸精灵对象 - 在 init() 函数中 - 取决于它面向的方向(在创建时随机分配)。僵尸精灵然后在走向边界时穿过循环。一旦他们到达边界然后改变方向,动画就不会更新为面向相同的方向,所以我最终会得到一堆月球行走的僵尸......并不是我想要的效果。如何在动画改变方向时更新动画?
"""
def __init__(self,x,y):
super(Zombie,self).__init__()
duration = 0.1
self.x = x
self.y = y
self.speed = 45
directions = [-1,1]
i = randint(0,1)
for index,direction in enumerate(directions):
if i == index:
self.direction = direction
img = load('sprites/zombiewalk.png')
img_grid = ImageGrid(img,1,12,item_width=32,item_height=48)
if self.direction == -1:
animation = Animation.from_image_sequence(img_grid[3:6],duration)
sprite = cocos.sprite.Sprite(animation)
self.add(sprite)
elif self.direction == 1:
animation = Animation.from_image_sequence(img_grid[6:9],duration)
sprite = cocos.sprite.Sprite(animation)
self.add(sprite)
def update(self,elapsed):
new_x = self.position[0] + self.speed * self.direction * elapsed
self.position = (new_x,self.y)
if self.position[0] < 0 or self.position[0] > 800:
self.direction *= -1
"""
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。