当文件明显位于我声明的位置时,如何解决FileNotFoundError出现的问题

问题描述

我目前正在制作2D RPG游戏,称为2Dgame。所有的照片和文件都位于python脚本所在的位置。

我的问题是pygame表示当我在同一脚本中对所有其他图像加载过程使用此方法时,找不到该图像。

这是我创建的用于在农民刺伤您时创建攻击粒子的类的代码

class PeasantStrike(pygame.sprite.Sprite):
def __init__(self,peasant):
    pygame.sprite.Sprite.__init__(self)
    self.angledir = math.degrees(math.atan((hero.rect.centerx - peasant.rect.centerx)//(hero.rect.centery - peasant.rect.centery)))
    print(self.angledir)
    self.frame = 0
    self.ani = 14
    self.animation = []
    for i in range(1,15):
        img = pygame.image.load(os.path.join(cwd,'particles\\peasantattack' + str(i) + ".png"))
        img = pygame.transform.scale(img,(20,14))
        img = pygame.transform.rotate(img,(self.angledir))
        img.set_colorkey(lime)
        self.animation.append(img)
        self.image = self.animation[0]
        self.rect = self.image.get_rect()
    self.rect.centerx = peasant.rect.centerx
    self.rect.centery = peasant.rect.centery

有人可以帮我解决这个问题吗?谢谢!

此外,这是失败时的输出

    img = pygame.image.load(os.path.join(cwd,'particles\\peasantattack' + str(i) + ".png"))
FileNotFoundError: No such file or directory.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)