Lesson 7: unit 3 Question


#1

Is there a way to get the background color of the grass to switch from green to red during the running of the program? How would a student code this? So in other words, he wants it to start green and then change to red after so many seconds.


#2

One way to do it would be to declare a variable at the beginning such as grassColor = “green” and then update the variable inside the draw loop. Here’s an example, although it isn’t so aesthetically pleasing … lol. https://studio.code.org/projects/gamelab/UaR4PT_BEeQpWet1AUURavZfeTLwlW2sEHTtb8ArIBI


#3

I should say the first one changes after the sun leaves the screen … you could also use a time effect instead of the event of the sun leaving the screen. This version has a 3 second timer. https://studio.code.org/projects/gamelab/V4uxb2dWZHAhMjI1hmHqkhMPIxuMKA6NETpgv71Q9wA


#4

Yeah, piggybacking on @mwood I think the answer is to use World.seconds which is a variable set to the number of seconds that have elapsed since the run button was hit.

if(World.seconds > 10){
//set the colors you want
}