Animation

We're going to explore how to give sprites multiple costumes and swap between them. For this project, we're just going to be making a simple animation, but there are lots of ways to use this pattern.
Play this demo in full screen.
1) Chose costumes for your sprite. If you are creating your own (or using costumes from a sprite sheet you like), it's best to have each costume be a similar size. Upload each costume as a separate sprite.
Play this demo in full screen.
2) Make a list that contains all the URLs for the costumes of your sprite.
3) Make a variable that keeps track of which costume in the list you'd like to display. (Note that Woof is zero-indexed, which means that we use '0' to refer to the first item in a list).
4) Every time you want to swap costumes, change your variable by 1 and then set your sprite's URL to the proper costume in the list. You'll need to make sure that the veriable gets set back to zero each time it gets to the end of the list of costumes.
Play this demo in full screen.
5) (Bonus) Add movement, and only advance the animation when the player is moving.
Play this demo in full screen.