繁体   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