My student stumped me with his question


My student was being extremely creative and created his own little game. He e-mailed me with this question but I’m stumped. At line 111, he tries to make this certain sprite pop up and then disappear slowly. He already made it so that it would disappear in the animation tab using animation.

When he runs the code, however, it is not animating. It’s just appearing in the first frame of that animation.

I have looked this up, but all I get is people saying that I have to add a background, which I already did in the draw function. I was wondering if you could help me with this.

I was able to load the project and look at it. He must have added more to it since the line for using that sprite is at line 170 or so now.

There are a few things it could be …

He is creating all of his variables inside the draw loop each time the space bar or up key is pressed. Normally, the creation statements (var petalSize = ) should be before the draw loop and then inside the draw loop, they would be updated with a statement such as (petalSize = );

Same thing with the unlucky and dead flower sprites. They probably shouldn’t be created inside the draw loop because each time they are created, they “start” all over at the first frame. Instead, they should be created outside the draw loop and then made visible inside the draw loop.

This should get him off to a good start, but after looking into that, please let us know if we can help further.

Mike