1

次のコードに問題があります。

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) を向いているとアニメーションがグリッチになります。

右に移動するときはまったく問題ありません。

何か案は?

4

2 に答える 2

0

あなたのifステートメントでは、ある場合は を変更self.owner.rect.rightし、他の場合は を変更しself.owner.rect.xます。

.rightこれは問題の一部である可能性があります。.x

于 2012-06-25T13:48:45.490 に答える
0

またはを使用してプレーヤーの位置を追跡する場合、Rect.centerまたはRect.centerxデフォルトのを使用するとtopleft、さまざまな幅が機能します。

ゲームによっては、スプライト シートを使用すると効果的な場合があります。

于 2012-06-23T18:37:03.410 に答える