I am making a simple game in pgzero, but the screen. function never seems to work correctly.
when I try to display text at the start like so:
screen.draw.text("Hello", (50, 30), color="orange")
it comes out saying screen is not defined
yet when I use it here:
def draw():
screen.clear()
bg.draw()
bread.draw()
it works perfectly fine
how do I fix this?
I have no familiarity with pgzero, but I installed it and played around, and when I put line inside the draw() function it runs fine:
def draw():
screen.draw.text("Hello", (50, 30), color="orange")
So it looks like draw()
needs to be there to show things on screen (and the screen
object is already part of draw()
. Let me know if you want an explanation of how this can happen (short answer: object inheritance).
Let me know if this solves your problem.
Looking at the documentation there's a few built-in functions (event hooks) like this that have special use. I think this is meant to get users unfamiliar with programming up and running quickly, but it's annoying that there seems to be no basic explanation in the documentation about this. And this is likely to confuse learners when they switch to learning a different language. However these things are always a work in progress so hopefully it improves.
More information: https://pygame-zero.readthedocs.io/en/stable/hooks.html