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()发布于 2011-06-23 01:34:07
我想我知道发生了什么,如果我没有错,你可能会认为
games.init(screen_width = 640,screen_height = 480,fps = 50)
就是和
scrwidth = 640
scrheight = 480
fps = 50
games.init(scrwidth, scrheight)但情况可能并非如此,参数int屏幕以不特定的顺序查找name=value对,因此仅有值对可能不起作用。但是,您可以这样做
scrwidth = 640
scrheight = 480
fps = 50
games.init(screen_width=scrwidth, screen_height= scrheight, fps=fps)
myscr = games.screen我猜由于您的大小设置不正确,文本中的x,y是绝对变量,所以您的文本可能会被弄乱
https://stackoverflow.com/questions/6443869
复制相似问题