Unit 3, Lesson 18

A student has created a free play with four if statements in a draw loop. Each if statement (direction) has a different color background. I am not able to help the student figure out to how to eliminate the blurriness with each new sprite direction.

**Game Lab - Code.org

**I appreciate it if someone could provide insight into this issue.

**What actually happens: Every time a new key is pressed the background color changes
**What I’ve tried: Of course, I’ve tried a solid background in the beginning of the draw loop stops the issue, but creates a epileptic effect for the watchers.

This is a really cute project! From what I can tell, the student may have used the wrong code for the movement. Try looking at this lesson for an example of how it might be changed to produce what the student is looking for.

The blurriness is coming from the way the background block is drawn. It only draws a background each time a key is pressed rather than each time through the draw loop.

Rather than using a background block inside each if statement, I would suggest using a single background block at the end of the code (still inside, but at the bottom of the draw loop).

To get the color change effect (which is soooo cool!!!), he could replace the background blocks with a statement such as: color="red"; (a different color statement in each conditional block).

Then, you would have to declare the variable color at the beginning of the code:
var color="white";

Then, the single background block at the end of the draw loop would just say background(color); (just the word color … no quote marks).

Doing this would make it so the color would update every time through the draw loop, but would use the color of the most recent arrow key press.

Let us know how it goes!!!


1 Like