Pygame在Pydev外面打破.

Rya*_*ley 4 python pygame

我和一群朋友创建了这个游戏,我现在正试图在linux中运行,

我们使用Aptana studio在Windows中使用python 2.7和Pygame开发它,并且代码在运行时完全可用.

当它下载到Linux它不会加载说它找不到文件.然后我尝试在Windows中通过CMD运行它,并且存在相同的错误.

到目前为止的错误是

Traceback (most recent call last):
  File "/home/user/Desktop/Raspberroids/mainmenu.py", line 144, in <module>
    showMenu()
  File "/home/user/Desktop/Raspberroids/mainmenu.py", line 107, in showMenu
    menu.init(['Start','About','Quit'], surface)
  File "/home/user/Desktop/Raspberroids/mainmenu.py", line 52, in init
    self.create_strukture()        
  File "/home/user/Desktop/Raspberroids/mainmenu.py", line 73, in create_strukture
    self.font = pygame.font.Font(self.font_path, self.fontsize)
IOError: unable to read font filename
Run Code Online (Sandbox Code Playgroud)

源代码位于:https: //github.com/ryanteck/RasPiThon/tree/master/Raspberroids/Source%20Code

发生在2.7和2.6上

有人可以帮忙吗?

slo*_*oth 5

您的字体路径data/coders_crux/coders_crux.ttf是相对的.

当您从源目录以外的其他目录开始游戏时,pygame无法找到该字体.


一个简单的解决方法是将以下行添加到脚本的顶部(mainmenu.py):

import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
Run Code Online (Sandbox Code Playgroud)

os.path.realpath(\__file__)将得到的路径,你的脚本,并与os.chdiros.path.dirname更改当前工作目录到脚本的目录.

这样,您使用的相对路径将起作用.