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()
For some reason, I am unable to print the score stri开发者_C百科ng in the position that I've assigned it to.
When I did the same thing without assigning variables to the given objects, I was able to do this successfully, but now I'm not that I've assigned it to a variable.
Any input would be appreciated. Thanks in advance.
EDIT: As requested, the working code.
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()
Here we are! Working code:
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()
I think i know whats happening, if i am not wrong you could be assuming that
games.init(screen_width = 640, screen_height = 480, fps = 50)
is the same thing as
scrwidth = 640
scrheight = 480
fps = 50
games.init(scrwidth, scrheight)
But that may not the case, the arguments int Screen look for name=value pairs in no particular order, so just value pairs may not work. You could however do this
scrwidth = 640
scrheight = 480
fps = 50
games.init(screen_width=scrwidth, screen_height= scrheight, fps=fps)
myscr = games.screen
I am guessing since your size was not set properly and x,y in text are absolute variables, your text may be messed up
精彩评论