Python 3.x 当文件清楚地位于我声明的位置时,如果出现FileNotFoundError,我如何解决此问题
我目前正在制作一个2D RPG游戏,叫做2D游戏。所有照片和文件都位于python脚本所在的同一位置 我的问题是pygame说,当我在同一个脚本中对所有其他图像加载过程使用此方法时,无法找到图像 这是我制作的一个类的代码,用来创建农民刺伤你时的攻击粒子Python 3.x 当文件清楚地位于我声明的位置时,如果出现FileNotFoundError,我如何解决此问题,python-3.x,image,pygame,Python 3.x,Image,Pygame,我目前正在制作一个2D RPG游戏,叫做2D游戏。所有照片和文件都位于python脚本所在的同一位置 我的问题是pygame说,当我在同一个脚本中对所有其他图像加载过程使用此方法时,无法找到图像 这是我制作的一个类的代码,用来创建农民刺伤你时的攻击粒子 class PeasantStrike(pygame.sprite.Sprite): def __init__(self, peasant): pygame.sprite.Sprite.__init__(self) self.an
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.