Changing background-Lesson 28 project

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]
What I expect to happen: he wants his background to change when [space] is pressed
What actually happens: he can’t get it to stay on the correct background
What I’ve tried: we tried KeyDown vs KeyWentDown and reordering some code

Hi @heather.caster ,

Great start screen. Because the draw loop checks the if statements 30x per second, as soon as you release the space key, the else statement background is run again. So, you have to create a variable at the very beginning of the game. I would call it something like bgState and set it to “start”. Then, the only thing the if keyDown==space does is change the variable bgState to “play”. Finally, create another if statement the controls background based on bgState. If bgState is “play”, the background() function runs, if it is “start” the else black background runs. By changing the state of the variable, the background remains until the variable is changed again.

I hope that make sense!

~Michelle

This helps a ton, thank you!