I’m trying to figure out how to create a rotating image effect using a sprite sheet in javascript. What I’m trying to do:
Two buttons:
Left button: Rotate 15 frames to the left.
Right button: Rotate 15 frames to the right.
I realize that there are jquery plugins that would allow me to easily do this, but I want to try it from scratch. Beyond the general idea, I don’t know where to proceed. Any tips would be greatly appreciated.
Check out this jsFiddle to see a working example
Based on your question, it sounds like you’re trying to learn how to animate a sprite and not actually rotate a single image. If so, here is how you would animate a sprite. Note: this uses an image of a man running. In your question, you asked about a rotating image effect. In either case, you are simply looking at different slice of a sprite and then animation is solely dependent on the sprite. As long as your sprite displays a rotating image then the image will appear to rotate.
If you need a plugin to actually rotate an image, see here.
JavaScript
HTML
CSS
Sample Sprite (1440×1480):
