2016-05-11 66 views
1

所以我嘗試使用pygame的創建一個遊戲和pyganim爲什麼在pygame/pyganim中使用os.path.join會導致錯誤?

我喜歡用文件夾到我的遊戲文件歸類到腳本,圖像,動畫等

出於某種原因,如果我使用的操作系統模塊和操作系統。 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

'frames [i] [1]'是字符串''m''。據推測,「幀[i]'是一些較大的字符串。 – TigerhawkT3

+2

我認爲這是因爲PygAnimation構造函數需要一個元組列表,但你傳遞了兩個字符串:'(Arcflash_list [4]),(Arcflash_list [5])''。你忘記爲這些幀添加整數,所以當pygame試圖從'frames [i] [1]'獲取元組中的整數時'它將索引字符串'Images \ Animation \ Arcflash \ Arcflash_005.png'。 –

+0

無論如何他們可能會繞過這個問題,id真的不必把我所有的動畫放到與我的腳本相同的文件夾中。這聽起來很愚蠢,但我真的很小心如何組織事情。 –

回答

0

這是因爲PygAnimation構造函數需要一個元組列表,但你傳遞了兩個字符串:(Arcflash_list[4]), (Arcflash_list[5])。你忘了爲這些幀添加整數,所以當pygame試圖從frames[i][1]得到元組中的整數時,它最終將索引字符串Images\Animation\Arcflash\Arcflash_005.png

相關問題