What I expect to happen: Student is trying to make it appear that the “camera” floats up into the sky when you click by moving the clouds downward What actually happens: when student tries to make it so they “float” down by changing the clouds y-axis slowly it just teleports it to the bottom of the page. What I’ve tried: He tried using a while loop and a for loop in the if statement to change the value of cloud1.y
Student #2
What I expect to happen: Student is trying to make it appear that the icicles are falling when the mouse is clicked What actually happens: when student tries to make it so they “float” down by changing the clouds y-axis slowly it just disappears from the screen What I’ve tried: He tried to do a mouseover and it would fall but if the mouse was not over it then it would disappear.
It appears to be the “while” block that is causing the problem in both programs. For whatever reason, code executed in while is executed so rapidly that the human eye can’t keep up with it.
When I changed it to if blocks, everything moved as expected, however, that still leaves the students with the challenge of getting that animation to take place only when the mouse is clicked.
Here’s one way to do it. Create a variable at the top of your code. I called mine “startAnimation.” Then, set it equal to zero. (0 meaning the animation hasn’t started yet).
Then, I suggest a single draw loop with the following inside.
All code required to create initial scene (ie backgrounds, shapes and drawSprites block.
A conditional block (if) that detects if (mouseWentDown) and sets the “startAnimation” block = to 1. (indicating the animation should start).
Another conditional block (if) that checks to see if startAnimation is equal to 1
A 3rd conditional (if) block nested inside the 2nd conditional block checking to see if the sprite’s y value < 400
Inside the 3rd conditional block, all of the code required to draw the scene (again) and the block that increases the y value of the cloud/icicle sprite.
When I did that, I could get it to work as you describe your students want it to.