Nikola Milutinovic
Nikola Milutinovic

Reputation: 742

Android frame by frame animation from png files

I'm trying to make frame by frame animation for my game.

I have model designed in Blender and I tried to export animation from Blender as series of PNG files and like that to play animation through AnimationDrawable. That happens to be a disaster. (slower animation and memory problem)

I also tried to make my own animator class to change the source/background of the ImageView and still I have the same problem.

Is there any way I can do this with openGL-ES or something similar but yet easy to use.

Thank you in advance!

Upvotes: 2

Views: 2765

Answers (4)

Nikola Milutinovic
Nikola Milutinovic

Reputation: 742

As I said, I did found a solution for this problem.

First thing you need to do is be ready to use some openGL ES.

  1. Create a square (2 triangles)
  2. Place it in the GLSurfaceView
  3. Change the texture of the square to create an animation.

This way you will leave the rendering to openGL which will do it faster and smoother.

Upvotes: 1

Enoobong
Enoobong

Reputation: 1734

Here is your solution Create an animation Drawable and the animating method see code below

AnimationDrawable mframeAnimation = null;

private void startAnimation()
{
     ImageView img = (ImageView)findViewById(R.id.ImageView_Juggle);

     BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash1); 
     BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash2); 
     BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash3); 

     // Get the background, which has been compiled to an AnimationDrawable object.
     int reasonableDuration = 250;
     mframeAnimation = new AnimationDrawable();
     mframeAnimation.setOneShot(false); // loop continuously
     mframeAnimation.addFrame(frame1, reasonableDuration);
     mframeAnimation.addFrame(frame2, reasonableDuration);
     mframeAnimation.addFrame(frame3, reasonableDuration);

     img.setBackgroundDrawable(mframeAnimation);

     mframeAnimation.setVisible(true,true);
     mframeAnimation.start();
}

This is just a straight forward method. Better Still create a thread the for animations. You can also create a method to dynamically add the frames. Hope this helps.

Upvotes: 1

ClayMontgomery
ClayMontgomery

Reputation: 2832

The best way to do this would be to export your model from Blender not as frames, but to a Collada or 3DSMax object file that contains your 3D model complete with textures and animations. Then use a library like assimp or the PowerVR SDK or a game engine running on Android to render the model in real time using OpenGL ES. This would be a bigger project of course, but the size of the data set would be much smaller and give you the ability to change the camera position and lighting at run time.

Upvotes: 0

TuPot
TuPot

Reputation: 31

Load images into a vector/array. Then switch images per frame. Possibly even changing based on time. I have done this opengl but never in opengl-es but this should be very similiar

Upvotes: 0

Related Questions