[英]Debugging Python pygame program
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()
出於某種原因,我無法在我指定的位置打印得分字符串。
當我在沒有為給定對象分配變量的情況下做同樣的事情時,我能夠成功地做到這一點,但現在我不是因為我已將它分配給變量。
任何輸入將不勝感激。 提前致謝。
編輯:根據要求,工作代碼。
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()
我想我知道發生了什么事,如果我沒有錯,你可以假設
games.init(screen_width = 640,screen_height = 480,fps = 50)
是一樣的
scrwidth = 640
scrheight = 480
fps = 50
games.init(scrwidth, scrheight)
但情況可能並非如此,參數int screen在沒有特定順序的情況下查找name = value對,因此只有值對可能不起作用。 但是你可以這樣做
scrwidth = 640
scrheight = 480
fps = 50
games.init(screen_width=scrwidth, screen_height= scrheight, fps=fps)
myscr = games.screen
我猜測,因為你的大小沒有正確設置,文本中的x,y是絕對變量,你的文字可能搞砸了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.