所以我试图用pygame和pyganim创建游戏
我喜欢使用文件夹将我的游戏文件分类为脚本,图像,动画等
出于某种原因,如果我使用os模块和os.path.join来查找文件所在的文件夹,同时尝试使用pyganimation创建动画对象,我会收到错误
File "H:\Projects\Arcflash\Arcflash.py", line 35, in <module>
Pyganim_Arcflash = pyganim.PygAnimation([(os.path.join("Images\Animation\Arcflash", 'Arcflash_001'))])
File "C:\Python27\lib\site-packages\pyganim\__init__.py", line 165, in __init__
frame = (frames[i][0], int(frames[i][1]))
ValueError: invalid literal for int() with base 10: 'm'
这是我当前代码的片段
# Imports
import pygame
import os
import math
import pyganim
# -- Initialize the Surface --
# Startup
pygame.init()
# Screen
size = (500, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption = ("Images - Rewrite")
pygame.mouse.set_visible(True)
clock = pygame.time.Clock()
# -- Assign Global Variables --
#Sets the color of pure white to a variable to be called
WHITE = (255, 255, 255)
#Sets the color of pure black to a variable to be called
BLACK = (0, 0, 0)
#Sets the background to an image
Menu_Background = pygame.image.load(os.path.join("Images", "menu_background.png"))
#Sets the player to an image
Player = pygame.image.load(os.path.join("Images", "player.png"))
#Sets the pointer to an image
Pointer = pygame.image.load(os.path.join("Images", "pointer.png"))
#Sets the dark and bright menu go button to an image
Menu_Go_Dark = pygame.image.load(os.path.join("Images", "go_dark.png"))
Menu_Go_Bright = pygame.image.load(os.path.join("Images", "go_bright.png"))
#Sets the dark and bright menu exit button to an image
Menu_Exit_Dark = pygame.image.load(os.path.join("Images", "exit_dark.png"))
Menu_Exit_Bright = pygame.image.load(os.path.join("Images", "exit_bright.png"))
#Assigns all the Arcflash text frames to a list
Arcflash_list = [os.path.join("Images\Animation\Arcflash", "Arcflash_001.png"),
os.path.join("Images\Animation\Arcflash", "Arcflash_002.png"),
os.path.join("Images\Animation\Arcflash", "Arcflash_003.png"),
os.path.join("Images\Animation\Arcflash", "Arcflash_004.png"),
os.path.join("Images\Animation\Arcflash", "Arcflash_005.png"),
os.path.join("Images\Animation\Arcflash", "Arcflash_006.png")]
#Sets the pyganimation list up for the arcflash text
Anim_Arcflash = pyganim.PygAnimation([(Arcflash_list[0], 100), (Arcflash_list[1], 100), (Arcflash_list[2], 100), (Arcflash_list[3], 100), (Arcflash_list[4]), (Arcflash_list[5])])
我的目标是让pyganim在图像文件夹中拍摄图像,而不是我得到错误。 帮助
(这个问题可能格式正确,也可能格式不正确,我对这个网站不太满意,而且我的上一个问题还没有得到好评)
编辑1:我试图解决这个问题
1:未使用列表
2:将os.path.join置于许多不同的位置,根据我认为逻辑上去的地方
实际上修复此错误的唯一事情是不使用文件夹,但这看起来非常糟糕,我对这种方法不感兴趣。我宁愿不使用pyganim。
答案 0 :(得分:0)
这是因为PygAnimation构造函数需要一个元组列表,但是你传递了两个字符串:(Arcflash_list[4]), (Arcflash_list[5])
。您忘记为这些帧添加整数,因此当pygame尝试从frames[i][1]
的元组中获取整数时,它最终会将字符串Images\Animation\Arcflash\Arcflash_005.png
编入索引。