来自png文件的Android逐帧动画

时间:2014-03-12 16:24:39

标签: android animation opengl-es

我正在尝试为我的游戏制作逐帧动画。

我在Blender中设计了模型,我尝试将Blender中的动画导出为 PNG 系列文件,并通过AnimationDrawable播放动画。 这恰好是灾难。 (较慢的动画和内存问题

我还尝试制作自己的动画类来更改 ImageView 的来源/背景,但我仍遇到同样的问题。

我有什么方法可以使用openGL-ES或类似但易于使用的东西。

提前感谢您!

4 个答案:

答案 0 :(得分:1)

以下是您的解决方案创建动画Drawable和动画方法,请参阅下面的代码

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();
}

这只是一种直截了当的方法。更好仍然为动画创建一个线程。您还可以创建一种动态添加帧的方法。希望这会有所帮助。

答案 1 :(得分:1)

正如我所说,我确实找到了解决这个问题的方法。

您需要做的第一件事是准备使用一些 openGL ES。

  1. 创建一个正方形(2个三角形)
  2. 将其放入GLSurfaceView
  3. 更改方块的纹理以创建动画。
  4. 通过这种方式,您可以将渲染保留为openGL,这样可以更快,更顺畅地进行

答案 2 :(得分:0)

将图像加载到矢量/数组中。然后每帧切换图像。可能甚至根据时间变化。我已经完成了这个opengl,但从未在opengl-es中完成,但这应该非常相似

答案 3 :(得分:0)

执行此操作的最佳方法是将模型从Blender导出为不是帧,而是导出包含3D模型的Collada或3DSMax对象文件,其中包含纹理和动画。然后使用像assimp或PowerVR SDK这样的库或在Android上运行的游戏引擎,使用OpenGL ES实时渲染模型。 这当然是一个更大的项目,但数据集的大小会小得多,并且您可以在运行时更改摄像机位置和照明。