Android:补间动画的位图

Geo*_*old 7 animation android sprite tween

我的应用程序通过在我的视图onDraw()方法中调用以下内容来实现自己的精灵:

  canvas.drawBitmap(sprite.getBitmap(), sprite.getX(), sprite.getY(), null);
Run Code Online (Sandbox Code Playgroud)

该应用程序是一个物理模拟,到目前为止,这已经很好了.但是现在我想通过在某些事件发生时为精灵变换图像来增强动画效果.

例如,当发生碰撞时,我想播放一个爆炸动画.我的想法是将普通的精灵位图替换为爆炸PNG,并使用Android"补间动画"使爆炸变大.

但Android 补间动画示例假定您ImageView在XML配置中静态定义了某个地方.

有没有办法在onDraw()使用补间动画时绘制位图动画?或者我需要转换我的精灵使用某种ImageView?如果是后者,你能指点一下Android中适当的精灵动画的例子吗?

谢谢

Aur*_*bon 10

我在java中构建了一个通用的Tween引擎,你可以使用它来动画任何东西,包括你的精灵.它针对Android和游戏进行了优化,因为它不会在运行时分配任何内容,以避免任何垃圾回收.此外,Tweens被汇集,所以真的:根本没有垃圾收集!

你可以在这里看到一个完整的演示作为Android应用程序,或者在这里作为WebGL html页面(需要Chrome)!

您所要做的就是实现TweenAccessor界面,为所有精灵添加Tween支持.您甚至不必更改Sprite类,只需创建一个SpriteTweenAccessor实现的类TweenAccessor<Sprite>,并在初始化时将其注册到引擎.只需看看GetStarted维基页面 ;)

http://code.google.com/p/java-universal-tween-engine/

商标

我还在构建一个可嵌入任何应用程序的可视化时间轴编辑器.它将具有类似于Flash创作工具和Expression Blend(Silverlight开发工具)的时间轴.

整个引擎都有大量文档记录(所有公共方法和类都有详细的javadoc),语法与Flash世界中使用的Greensock的TweenMax/TweenLite引擎非常相似.请注意,它支持每个罗伯特·彭纳缓和方程.

// Arguments are (1) the target, (2) the type of interpolation, 
// and (3) the duration in seconds. Additional methods specify  
// the target values, and the easing function. 

Tween.to(mySprite, Type.POSITION_XY, 1.0f).target(50, 50).ease(Elastic.INOUT);

// Possibilities are:

Tween.to(...); // interpolates from the current values to the targets
Tween.from(...); // interpolates from the given values to the current ones
Tween.set(...); // apply the target values without animation (useful with a delay)
Tween.call(...); // calls a method (useful with a delay)

// Current options are:

yourTween.delay(0.5f);
yourTween.repeat(2, 0.5f);
yourTween.repeatYoyo(2, 0.5f);
yourTween.pause();
yourTween.resume();
yourTween.setCallback(callback);
yourTween.setCallbackTriggers(flags);
yourTween.setUserData(obj);

// You can of course chain everything:

Tween.to(...).delay(1.0f).repeat(2, 0.5f).start();

// Moreover, slow-motion, fast-motion and reverse play is easy,
// you just need to change the speed of the update:

yourTween.update(delta * speed);
Run Code Online (Sandbox Code Playgroud)

当然,没有提供构建强大序列的方法,没有补间引擎是完整的:)

Timeline.createSequence()
    // First, set all objects to their initial positions
    .push(Tween.set(...))
    .push(Tween.set(...))
    .push(Tween.set(...))

    // Wait 1s
    .pushPause(1.0f)

    // Move the objects around, one after the other
    .push(Tween.to(...))
    .push(Tween.to(...))
    .push(Tween.to(...))

    // Then, move the objects around at the same time
    .beginParallel()
        .push(Tween.to(...))
        .push(Tween.to(...))
        .push(Tween.to(...))
    .end()

    // And repeat the whole sequence 2 times
    // with a 0.5s pause between each iteration
    .repeatYoyo(2, 0.5f)

    // Let's go!
    .start();
Run Code Online (Sandbox Code Playgroud)

我希望你确信:)有很多人已经在他们的游戏或Android UI动画中使用引擎.