簡體   English   中英

為什么翻轉我的精靈會導致它移動奇怪

[英]Why does flipping my sprites cause it to move weird

我正在制作一個 pyGame 游戲,我決定水平翻轉它,而不是讓精靈兩側都可以控制圖像中心。

那是我的圖紙 function:

    def draw(self, screen):
        screen.blit(pygame.transform.flip(self.image, self.flip, False), self.rect)

這就是我存儲所有imgs的方式:

animation_types = ['stand', 'walk', 'jump', 'attack1', 'attack2', 'attack3']
        for animation in animation_types:
            #reset temporary list of images
            temp_list = []
            #count number of files in the folder
            num_of_frames = len(os.listdir(f'sprites/{self.char_type}/{animation}'))
            for i in range(num_of_frames):
                img = pygame.image.load(f'sprites/{self.char_type}/{animation}/{i}.png')
                img = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height() * scale)))
                temp_list.append(img)
            self.animation_list.append(temp_list)

您需要反轉翻轉面的列表。將列表reverse到位:

temp_list.reverse()            
self.animation_list.append(temp_list)

或 appendreversed列表:

self.animation_list.append(reversed(temp_list))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM