PyGame动画精灵面临左侧问题

时间:2012-06-23 18:08:23

标签: animation sprite pygame

我遇到以下代码问题:

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

由于精灵有不同的宽度,我面对的时候会出现毛刺的动画 左(-1)。

移动RIGHT时没有任何问题。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

如果您使用Rect.centerRect.centerx与默认topleft跟踪玩家的位置,则可以使用不同的宽度。

根据你的游戏,使用精灵表可能会有所帮助。

答案 1 :(得分:0)

在您的if声明中,在一种情况下,您更改了self.owner.rect.right,而在另一种情况下,您更改了self.owner.rect.x

这可能是问题的一部分,因为当你向左移动时,你正在改变.right而不是.x

相关问题