Game Lab Unit 3 Lesson 14

I have a student who has the animation created for sonic the hedge hog but then when he sees it in game lab it doesn’t appear to be moving like it shows it is in the animation tab. What is he doing wrong?

Ms. Pomerenke,

Great question, First all the setup for the level (background and sonic sprite creation) needs to be done outside of the draw loop, otherwise it’s creating a new one each time. So the only blocks of code you should have in the draw() loop is the if statement, sonic.setAnimation and sonic.scale. Once that is done, sonic does change to the gif version for a brief while, but then stops - so still not answering your question completely, but getting closer (problem solving steps!).

As for the gif of Sonic, I’m asking the developers because I know that gifs haven’t been supported in the past, but I’m curious as to why this sonic gif seems to work just briefly. Hopefully we’ll get an answer before school on Monday!

Brad

Thanks for the reply. It shouldn’t be a gif as he created images in the animation tab and over layed them to show movement. I didn’t look obviously at the draw loop so that fixed it somewhat like you said. Any further help will be much appreciated.

It looks to me that Sonic just needs to be moved along with changing the way he looks when hitting the right arrow. His x position would need to be added to for every press of the right arrow along with the change in animation. I don’t know much about the .gif files either though. I’ll share this with the powers that be to see if they might have some ideas for you though.

Hi, were you able to get this to work? In the linked version, I still see everything being set up in the draw loop, so I’m not sure whether the student is working on a different draft.

Thanks,
Elizabeth

No, I have changed everything in the code up to that it still only spins once…Here is an uploaded share
https://studio.code.org/projects/gamelab/u7n4F6rPGB10TR52lk1i6pXlWAFrKxTPzFqstzDLL6U

The reason that sonic isn’t animating when he runs is because the sprite is getting its animation reset every time the draw loop runs while the right key is being held down. That means that it’s only showing the first frame of the animation every time. The student needs to set the animation only once when the key first goes down. They will probably need more than one conditional.

Elizabeth