pygame说它找不到目录

dwbf0jvd  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(205)

# load all images for the players

    animation_types = ['Idle', 'Run', 'Jump']
    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'Assets/{self.char_type}/{animation}'))
        for i in range(num_of_frames):
            img = pygame.image.load(f'Assets/{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)

我是python和pygame的新手,正在制作我的第一个游戏。我遇到了一个问题,我试图访问动画文件。对于空闲动画,目录为assets/player/idle。文件夹内有5幅图像。运行代码时,我收到以下错误:

img = pygame.image.load(f'Assets/{self.char_type}/{animation}/{i}.png')
FileNotFoundError: No such file or directory

我非常确定问题出在动画文件夹中的图像上,因为我确保找到了其他文件夹,并且它们都很好。我真的不知道该怎么办。如果你需要完整的脚本,那么我可以发送它。非常感谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题