作者purestone (天空之子)
看板Python
標題[問題] 無法開啟
時間Thu May 1 19:56:57 2014
以下是我照抄寫的部分python遊戲程式碼
import pygame
from pygame.locals import
pygame.init()
width, height = 640, 480
screen=pygame.display.set_mode((width. height))
player = pygame.images.load("resources/images/dude.png")
error:couldn't open resources/images/dude.png
就像大家看到的,無法打開 resources,想請問是為什麼呢?? 我有先下載相關檔案在
電腦文件夾裡了啊...
我的作業系統是ubuntu12.04,用python2.7寫,以上程式碼是參照Beginning Game
programming for Teens with python抄的,網址是
http://www.raywenderlich.com/24252/beginning-game-programming-for-teens-with-python
拜託高手指點迷津一下,謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.169.205.162
※ 文章網址: http://webptt.com/m.aspx?n=bbs/Python/M.1398945422.A.569.html
1F:→ funnypeter:use absolute path not relative path 05/01 20:27
2F:→ funnypeter:that's a common error 05/01 20:28
3F:推 funnypeter:try a absolute path such as ~/script/images/.png 05/01 20:32
→ funnypeter:mkdir such path first of cours
請問F大,你是說最下面那行
要打player = pygame.images.load("script/images/dude.png ")嗎??e. 05/01 20:3
4F:推 Microscft:么壽 網頁拉到最下面很驚人 這是一個13歲男孩寫的 05/01 20:46
※ 編輯: purestone (118.169.205.162), 05/01/2014 22:48:51
5F:→ Microscft:...... 你是不是英文不太好 05/02 00:30
6F:→ Microscft:你先去google什麼叫絕對路徑什麼叫相對路徑 05/02 00:31
7F:→ Microscft:然後再去yahoo辭典查such as是什麼意思 05/02 00:32
8F:推 jokester:python開啟文件時會展開~嗎? 05/02 00:50
9F:→ apua:通常不會; 一樓應該只是提醒 05/02 02:04
10F:推 funnypeter:絕對路徑:最前面有/開始 05/02 04:55
11F:→ funnypeter:相對路徑沒有, 通常找不到是路徑設定錯誤 05/02 04:56
12F:→ funnypeter:改成絕對路徑就不會發生找不到路徑的情況 05/02 04:57
13F:→ funnypeter:~的意思是你的家目錄, /home/username 05/02 04:58
14F:推 funnypeter:~/script/images/.png 意思是/home/username/script/im 05/02 05:00
15F:→ funnypeter:ages/.png 05/02 05:00
16F:→ funnypeter:當然你要先mkdir建立該目錄 05/02 05:01
17F:→ funnypeter:路徑改成 我上述說的絕對路徑看看 05/02 05:02
18F:→ funnypeter:這是初學者常見的錯誤 05/02 05:03
19F:推 funnypeter:dude.png當然要移動到該目錄內 05/02 05:05
20F:→ funnypeter:username改成你的名字 05/02 05:06
21F:→ funnypeter:我這裡舉的路徑只是例子,你也可以用~/images/.png 05/02 05:07
22F:推 funnypeter:你試試看 cd~ 05/02 05:09
23F:→ funnypeter:然後打pwd就知道了 05/02 05:10
24F:→ funnypeter:自己寫程式不要都照抄,要自己改環境變數,這是很常見 05/02 05:11
25F:→ funnypeter:的修改 05/02 05:11
26F:→ purestone:謝謝! 05/02 06:43