My students love making their sprites move in different directions off of their pages, but is there a way to make the sprites reappear without having to refresh the page manually?
I thought there was a level somewhere in unit 3 that teaches this, but I can’t find it right now. Basically, you have to use a conditional (if block) that is placed inside the draw loop. Assuming the sprite is moving to the right, It would check to see if the x value of a sprite is greater than ˜400 (meaning it would have traveled off the right side of the screen) and then change it to a negative number (to the left of the screen) at which point, it’s movement to the right would bring it back on the screen.
Sometimes, you have to adjust the numbers to a number larger than 400 to make sure the sprite has enough time to fully exit and your negative number has to be adjusted as well depending on the size of the sprite. A little trial and error to make things more smooth.
If this doesn’t make sense, let me know and I’m happy to explain better or give you an example.
Thank you so much this was so so helpful! One last question, if my students code an object , such as an ellipse, I know they can get it to randomly move using “randomNumber” for the x or y position. However, is there a way to make a coded object move smoothly across the screen, such as gradually increasing the x or y value?
Yes, you can animate non-sprite objects such as ellipses, but it requires using a variable for the x & y properties.
Here is an example. Ellipse Animation
Hope this helps!
Thank you so much! This was so helpful!