# What's the best way to create animations when doing Android development?

I'm trying to create my first Android game and I'm currently trying to figure out (with someone that will do the drawings and another programmer) what the best way to create animation is. (Animations such as a character moving, etc.)

At first, the designer said that she could draw objects/characters and animate them with flash so she didn't have to draw every single frame of an action. The other programmer and I don't know Flash too much so I suggested extracting all the images from the Flash animation and making them appear one after the other when the animation is to start.

He said that would end up taking too much resource on the CPU and I tend to agree, but I don't really see how we're supposed to make smooth animations without it being too hard on the hardware and, if possible, not have the designer draw every single frame on Adobe Illustrator.

Can an experienced Android game developper help me balance this out so we can move on to other parts of the game as I have no idea what the best way to create animations is.

If you're considering 2D animation, rendering one sprite and then another will not be a problem for the device (unless your sprites are huge).

Below is a typical animation sprite that is the first one I found with a little searching. This is a commonly used technique and there are lots of websites that offer free (and otherwise, always check the license) spritesheets.

Image + author source: here

The green is set as the transparent colour of the image so that you don't have any unwanted areas of colour. You will need to know the coordinates of each animation in the animation sequence in the spritesheet in order to play them.

For Android, we can take a look at an open source game engine by Chris Pruett (formerly of Google) called Replica Island. The source code is available, and we can look at his SpriteAnimation.java and SpriteComponent.java.

A SpriteAnimation is simply created with a frame count and a unique ID and each actor in the game can have multiple animations. The SpriteAnimation can be given a number of AnimationFrames, each with a duration in milliseconds. This means that different animations can be swapped in and out depending on if the character moves or attacks etc (see in AnimationComponent.playAnimation(int id)).

Each iteration of the game loop, the AnimationFrame's getFrame(float time) is called, and it checks how much time has passed since the last main loop iteration and decides which frame to play next, then returns the frame to get sent off to the rendering system. This allows it to skip animation frames if the animation is going too slowly.

I hope this example works, and you can see it being used in the actual game on the Android Marketplace here.

• Thanks a lot for the well explained and detailed answer! I'll see how I can adapt this to my game. This is very helpful! – Adam Smith Oct 2 '11 at 7:34
• @AdamSmith: Using sprite-sheets like that is the best way for 2D animations. It doesn't matter if your artist creates the animations in flash or another program, as long as he can export the animation to images which you can then pack into a sprite-sheet – bummzack Oct 2 '11 at 8:10
• @bummzack That's the kind of answer I was hoping for, thanks! – Adam Smith Oct 2 '11 at 9:18
• @AdamSmith it should be noted also (to avoid confusion) that Replica Island doesn't actually use sprite sheets, it uses single files. Discussion of why spritesheets are useful can be found here and (with more detail) here. – Martin Foot Oct 2 '11 at 9:32
• @Martin Foot, You have given a very nice explanation. But i have still confusion, i am having 10-15 type of animation and i have Frames of each of them with the size of 320x480 which you can say a full screen animation. So what you suggest me that should i got for SpriteSheet or Single animation source file? I am too confuse in what to use. Please kindly suggest me the best way.. Thanks a lot.... – Scorpion Dec 28 '11 at 4:10