安卓:位图的补间动画 [英] Android: tween animation of a bitmap

查看:283
本文介绍了安卓:位图的补间动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序通过调用以下实现自己的精灵我的观点的的OnDraw()方法:

My app implements its own sprites by calling the following in my view's onDraw() method:

  canvas.drawBitmap(sprite.getBitmap(), sprite.getX(), sprite.getY(), null);

该应用程序是一个物理模拟,到目前为止这工作具有重要意义。但现在我想用图像之间变形的精灵,当某些事件发生时提高了动画。

The app is a physics simulation, and so far this has worked out great. But now I'd like to enhance the animation by morphing between images for the sprites when certain events occur.

有关示例 - 当碰撞发生时,我想打一个爆炸的动画。我的想法是与爆炸的PNG的取代通常的子画面位图,并使用机器人吐温动画,使爆炸长得更大。

For example- when a collision happens, I would like to play an animation of an explosion. My idea was to replace the usual sprite bitmap with that of an explosion PNG, and use Android "tween animation" to make the explosion grow larger.

但Android的补间动画的例子假设你有一个的ImageView 在XML配置中定义静态的某个地方。

But the Android tween animation example assumes that you have an ImageView defined somewhere statically in your XML configuration.

有没有办法所画的OnDraw动画位图()使用补间动画?或者,我需要将我的精灵使用某种的ImageView 的?如果是后者,你可以点我到正确的精灵动画在Android的一个例子?

Is there a way to animate a bitmap as drawn in onDraw() using tween animation? Or do I need to convert my sprites to use some sort of ImageView? If the latter, can you point me to an example of proper sprite animation in Android?

感谢

推荐答案

我建了一个通用的吐温引擎在java中,你可以用它来制作动画任何东西,包括你的精灵。这对Android和游戏优化的,因为它在运行时不分配任何东西,以避免任何垃圾收集。此外,吐温汇集,所以真的!没有垃圾收集所有

I built a generic Tween Engine in java that you can use to animate anything, including your sprites. It's optimized for Android and games because it does not allocate anything at runtime, to avoid any garbage collection. Moreover, Tweens are pooled, so really: no garbage collection at all!

您可以在这里看到一个完整的演示作为一个机器人应用程序或这里作为一个WebGL的HTML页面(需要Chrome浏览器)!

You can see a complete demo here as an android application, or here as a WebGL html page (requires Chrome)!

所有你需要做的是落实 TweenAccessor ​​界面添加吐温支持所有的精灵。你甚至不必改变你的Sprite类,只需要创建一个 SpriteTweenAccessor ​​类实现 TweenAccessor<雪碧> ,并注册到引擎在初始化。只要看看在 GetStarted维基页面;)

All you have to do is implement the TweenAccessor interface to add Tween support to all your sprites. You don't even have to change your Sprite class, just create a SpriteTweenAccessor class that implements TweenAccessor<Sprite>, and register it to the engine at initialization. Just have a look at the GetStarted wiki page ;)

<一个href="http://$c$c.google.com/p/java-universal-tween-engine/">http://$c$c.google.com/p/java-universal-tween-engine/

我还建设了可视化的时间线编辑器,可以嵌入到任何应用程序。这将有类似Flash创作工具和防爆pression混合(一个Silverlight开发工具)。

I'm also building a visual timeline editor that can be embedded in any application. It will feature a timeline similar to the Flash authoring tool and Expression Blend (a Silverlight dev tool).

整个发动机在很大程度上证明(所有公共方法和类都有详细的javadoc),以及语法非常相似,采用的是闪存世界Greensock的TweenMax / TweenLite的引擎。需要注意的是,它支持所有的罗伯特·彭纳缓动方程。

The whole engine is heavily documented (all public methods and classes have detailed javadoc), and the syntax is quite similar to Greensock's TweenMax/TweenLite engine that is used in the Flash world. Note that it supports every Robert Penner easing equation.

// 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);

当然,没有吐温引擎将是不完整的提供了一个方法来建立强大的序列:)

Of course, no tween engine would be complete without providing a way to build powerful sequences :)

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

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

I hope you're convinced :) There are a lot of people already using the engine in their games or for android UI animation.

这篇关于安卓:位图的补间动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆