我在使用以下代码时遇到问题:
def handle_image_flip(self, old_rect):
new_rect = self.last_frame.get_rect()
self.owner.rect = new_rect
self.owner.rect.y = old_rect.y
if self.owner.facing == -1:
self.owner.rect.right = old_rect.right
else:
self.owner.rect.x = old_rect.x
def animate(self, tick):
if tick - self.last_update > self.image_info[self.action]["frame_rate"]:
self.last_frame = self.get_next_frame(tick)
old_rect = self.owner.rect.copy()
self.owner.image = self.last_frame
self.handle_image_flip(old_rect)
self.last_update = tick
在哪里:
self.owner is the sprite this piece of code handles
self.owner.facing is the direction the sprite is facing
self.last_frame is the new image I want to display
由于精灵有不同的宽度,我在面对 LEFT (-1) 时会出现故障动画。
向右移动时没有任何问题。
有任何想法吗?