Background change in game lab unit3

I have a student who wants her background to change and stay changed in line 133. She wants the space bar to be pressed and the background to stay changed. Right now it only stays changed when the space is pressed.

We’ve used keydown and keywent down.

Help please

(https://studio.code.org/projects/gamelab/mYiZD4nkkBdPtzdjCI_V3NA_4KL5dGEtwReiqI1MCgA)

What is happening is that both the intro (white screen) AND the background function are always being called in the draw loop. So even when the space key is down and calling the background function, as soon as it is released the intro function is called again.

There are probably MANY fixes for this but what I did was created a variable that starts at 0. When the space bar is pressed, one is added to the variable. IF the variable >=1, the background function is run, else the intro function is run. It seemed to work. Good luck!

25%20PM 32%20PM
Michelle

1 Like

Thank you so much we will try it out today in class!