2011-06-22 39 views
0
from livewires import games, color 

#Creating and validating the pygame screen. 
scrwidth = 640 
scrheight = 480 
fps = 50 
myscr = games.Screen(scrwidth, scrheight) 
#Loading an image into memory to create an image object 
wall_image = games.load_image("wall.jpg", transparent = False) 
myscr.set_background (wall_image) 
#Printing Arbitary Score 
texty = games.Text(value = "Score: 2048321", 
        size = 70, 
        color = color.black, 
        x = 400, 
        y = 30) 
myscr.add(texty) 
myscr.mainloop() 

出於某種原因,我無法在分配給它的位置打印分數字符串。調試Python pygame程序

當我做同樣的事情沒有分配變量給定的對象,我能夠成功地做到這一點,但現在我不是我已經把它分配給一個變量。

任何輸入,將不勝感激。提前致謝。

編輯:根據要求,工作代碼。

from livewires import games, color 

games.init(screen_width = 640, screen_height = 480, fps = 50) 

wall_image = games.load_image("wall.jpg", transparent = False) 
games.screen.background = wall_image 

score = games.Text(value = 1756521, 
        size = 60, 
        color = color.black, 
        x = 550, 
        y = 30) 
games.screen.add(score) 

games.screen.mainloop() 

在這裏,我們是!工作代碼:

from livewires import games, color 

#Creating and validating the pygame screen. 
scrwidth = 640 
scrheight = 480 
fpsy = 50 
games.init(screen_width = scrwidth, screen_height =scrheight, fps = fpsy) 
myscr = games.screen 
#Loading an image into memory to create an image object 
wall_image = games.load_image("wall.jpg", transparent = False) 
myscr.background = wall_image 
#Printing Arbitary Score 
texty = games.Text(value = "Score: 2048321", 
        size = 70, 
        color = color.black, 
        x = 400, 
        y = 30) 
myscr.add(texty) 
myscr.mainloop() 
+0

你能提供的代碼版本你談論,你「在沒有給給定對象分配變量的情況下做同樣的事情」,它的工作原理? –

+1

你可以在分配變量之前發佈初始代碼嗎? –

+0

當然,在沒有的代碼下發布。請稍等。 – Louis93

回答

2

我想我知道發生了什麼,如果我沒看錯,你可以假設

games.init(SCREEN_WIDTH = 640,SCREEN_HEIGHT = 480, FPS = 50)

是一回事

scrwidth = 640 
scrheight = 480 
fps = 50 
games.init(scrwidth, scrheight) 

但事實可能並非如此,參數詮釋畫面看起來在沒有特定的順序name = value對,所以才值對可能無法工作。然而,你能做到這一點

scrwidth = 640 
scrheight = 480 
fps = 50 
games.init(screen_width=scrwidth, screen_height= scrheight, fps=fps) 
myscr = games.screen 

我猜,因爲未正確設置你的尺寸和X,Y文本是絕對的變數,您的文字可能會搞砸

+0

我現在得到這個: TypeError:__init __()得到了一個意外的關鍵字參數'screen_width' – Louis93

+0

我的壞,它應該是init不是屏幕,爲什麼你刪除init?所以用games.init(screen_width = scrwidth,screen_height = scrheight,fps = fps)替換myscr = games.Screen(scrwidth,scrheight),然後添加myscr = games.screen –

+0

明白了,謝謝。同樣的,有幾件事我沒有學會如何正確輸入(如背景),但現在都很好。如果你想再次看到它,我已將工作副本放在問題中。 – Louis93