AS3 - 在整数上使用 Tween?

发布于 2024-12-24 18:43:44 字数 650 浏览 1 评论 0原文

以前没有使用过 Tween 函数,所以我需要一点帮助。

我想在两个整数之间进行补间。

例子: 我缓冲 360 帧(图像)。

我想跳到第 100 帧(从第 1 帧开始),但我想使用缓动使其看起来更好。

我所需要的只是补间一个将用于当前显示图像的整数。


到目前为止一切顺利,但我不知道如何在补间中更新我的图像:

        public function timerEvent(event:TimerEvent):void{
            TweenLite.to(this, 2, {_currentFrame: 50, ease:Strong.easeOut}); 

            if (_currentFrame>=358) _currentFrame -= 359;
            if (_currentFrame<0) _currentFrame += 359;
            var myBitmap:Bitmap = new Bitmap(buffer[_currentFrame+1]);
            myBitmap.smoothing = true;
            imageBuffer.data = myBitmap;
        }

Not been using the Tween functions before, so I'd like a little help.

I want to tween between two integers.

Example:
I buffer 360 frames (images).

I want to skip to frame 100 (from frame 1), but I want to use ease to make it look better.

All I need is to tween an integer that I will use for the current image displayed.


So far so good, but I'm not getting how to update my image in the tween:

        public function timerEvent(event:TimerEvent):void{
            TweenLite.to(this, 2, {_currentFrame: 50, ease:Strong.easeOut}); 

            if (_currentFrame>=358) _currentFrame -= 359;
            if (_currentFrame<0) _currentFrame += 359;
            var myBitmap:Bitmap = new Bitmap(buffer[_currentFrame+1]);
            myBitmap.smoothing = true;
            imageBuffer.data = myBitmap;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕头说它不想醒 2024-12-31 18:43:44

我强烈建议使用 Greensock 的 TweenLite 和 TweenMax 库,而不是内置的 Tweening 函数。

http://www.greensock.com/tweenmax/

这些的美妙之处在于你可以补间任何对象的数字属性,并应用缓动,您甚至可以使用 TweenMax 中内置的帧插件直接补间 MovieClip 的帧:

import com.greensock.TweenMax;
import com.greensock.easing.Strong;

TweenMax.to(this,2,{frame:100,ease:Strong.easeOut});

要补间计数器值同样简单,因为它不需要您可以使用较轻的 TweenLite 框架插件:

import com.greensock.TweenLite;
import com.greensock.easing.Strong;

var counter:int = 0;

TweenLite.to(this,2,{counter:100,ease:Strong.easeOut});

编辑以包含新代码

当补间运行时,您可以捕获更新事件,该事件允许您对参数的当前值执行操作。然后你可以做这样的事情:

TweenLite.to(this, 2, {_currentFrame: 50, ease:Strong.easeOut, onUpdate:updateCallback}); 

function updateCallback():void
{
    var myBitmap:Bitmap = new Bitmap(buffer[_currentFrame+1]); 
    myBitmap.smoothing = true; 
    imageBuffer.data = myBitmap;
}

I would seriously recommend using Greensock's TweenLite and TweenMax libraries over the built in Tweening functions.

http://www.greensock.com/tweenmax/

The beauty of these is that you can tween any numeric property of an object, and apply easing, and you can even tween frames of a MovieClip directly by using the Frames plug that is built into TweenMax:

import com.greensock.TweenMax;
import com.greensock.easing.Strong;

TweenMax.to(this,2,{frame:100,ease:Strong.easeOut});

To Tween a counter value is just as easy, and because it doesn't require the Frames plugin you can use the lighter TweenLite:

import com.greensock.TweenLite;
import com.greensock.easing.Strong;

var counter:int = 0;

TweenLite.to(this,2,{counter:100,ease:Strong.easeOut});

Edit to include new code

As the tween runs you can capture an update event which lets you perform actions on the current values of your parameters. You could then do something like this:

TweenLite.to(this, 2, {_currentFrame: 50, ease:Strong.easeOut, onUpdate:updateCallback}); 

function updateCallback():void
{
    var myBitmap:Bitmap = new Bitmap(buffer[_currentFrame+1]); 
    myBitmap.smoothing = true; 
    imageBuffer.data = myBitmap;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文