One of my students wants the dragon to rotate after it is clicked. We can’t seem to figure out how to make that happen. Here is a link to the code.
Hello again, @heath.kelley,
A few suggestions may help your student improve the program and get the dragon rotating.
- Create the dragon at the beginning of the program along with the other sprites, but make it invisible. Then, when the boy is clicked, make the dragon visible (and perhaps the boy invisible). When you create it inside the draw loop, it can be created more than once and behavior becomes less predictable.
- Think about using a variable as a trigger to start the rotation. If you set the variable = to false and then when the boy is clicked change it to true, that’s the switch. Another conditional statement can be set to see if the variable is true and if it is true, start the spinning.
I think your student is almost there. This is a fun looking project!
Thank you for getting back to me again!
Here is what I came up with - https://studio.code.org/projects/gamelab/zlRPaRJurfvclKX3hQwk0Wr2f_ujwatP5WGjbe-BIUg. I’m going to give her your suggestions and coach her through this code. I appreciate your help. If you see anything else in this code that needs work please let me know. This is my first year teaching unit 3 code.org.
@heath.kelley, Yes. That does looks great. If he wanted it to stay rotating (rather than just while the mouse is over it), you could change the 2nd conditional block to read “if dragonRotation ==true”. That would use the toggle switch and the dragon would continue to rotate no matter where the mouse is.
Okay, that makes sense. I was wondering how to make that work. Here is my updated code - https://studio.code.org/projects/gamelab/_GnF4FMtLsZZFL5SJf1PKkjohCmYyB7plkVRidBLFL4