How to do a sprite animation in android using OpenGL ES?

What i have done :

Now I am able to draw a rectangle and apply my texture(Spritesheet) to it

What I need to know :

Now the rectangle shows the whole sprite sheet as a whole How to show a single action from sprite sheet at a time and make the animation

It will be very help full if anyone can share any idea's , links to tutorials and suggestions.

Advanced Thanks to All

share|improve this question
You can find the answer here: gamedev.stackexchange.com/questions/37510/… – Marco Martinelli Oct 15 at 8:21
You might consider using libGDX for Android based game development. It is an open source Java library with good performance. Sprite animation: code.google.com/p/libgdx/wiki/SpriteAnimation – nosferat Nov 14 at 10:19
feedback

3 Answers

You need to do the right UV mapping to be able to see only one frame of your sprite sheet.

For the animation the trick is to use

glMatrixMode(GL_TEXTURE);
glTranslatef(u, v, 0);

where u and v are the coordinates of the current frame in UV space.

You can find more info here: sprite animation in openGL

share|improve this answer
feedback

AndEngine provides a good way to draw animated sprites. It has a class AnimatedSprite which will do a lot of work for you. Here are the steps :

  1. Get the BitMapTextureAtlas

bitmapTextureAtlas = new BuildableBitmapTextureAtlas(getTextureManager(), 480, 200, TextureOptions.NEAREST);

2.Get the TiledTextureRegion for your spirtesheet

yourTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(bitmapTextureAtlas, context, "yourspritesheet.png", /*sprite rows*/, /*sprite columns*/);

3.Finally create the AnimatedSprite and attach it to the scene

AnimatedSprite yourSprite = new AnimatedSprite(40, 40, yourTextureRegion, this.getVertexBufferObjectManager());
yourSprite.animate(100);
yourScene.attachChild(yourSprite); /**attach this spirte to the scene**/

For further reference look : https://github.com/nicolasgramlich/AndEngineExamples

share|improve this answer
feedback

The optimized way would be to have one texture with all the steps in your animation, like movie frames. As it is a texture, each frames has initial coordinates and a common frame width and height. Draw one quad and change the uv coordinates of the quad to match the frame you want to draw in the texture. Marco Martilleni pointed to a good tutorial.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.