Adobe Flex 计时器事件

发布于 2024-09-07 02:00:44 字数 513 浏览 3 评论 0原文

我只是有一个关于 Adob​​e Flex 的 Timer 和 TimerEvent (flash.events.TimerEvent & flash.utils.Timer) 的简单问题。

我目前正在开发一个项目,其中我需要偶尔改变速度、停止和播放 swf 动画(加载到加载器并实例化为 ByteArray)。

例如,我有一辆以 40 公里/小时的速度行驶的移动汽车(swf 动画)。然后我有一个按钮,可以按 40 公里/小时的增量更改速度。所以基本上,每当我按下按钮时,游戏车就应该按增量改变速度。困难的部分是,我已经在 Adob​​e Flex 中进行了此操作,但它还没有改变速度。我的意思是,它仅按照我在 Flash 上创建 swf 文件时设置的关键帧间隔移动(也就是说,每个关键帧 30 帧间隔)。

简而言之,我只需要根据我要求改变的增量来改变速度。一位同事告诉我使用 Flex 的 Timer 和 TimeEvent,但我似乎不太掌握它的窍门,因为我对 ActionScript 世界还是个新手。

我希望有人能帮助我。谢谢 :)

I just have a one quick question on Timer and TimerEvent (flash.events.TimerEvent & flash.utils.Timer) of Adobe Flex.

I am currently working on a project wherein I need to occasionally change speed, stop and play an swf animation (loaded to a loader and instantiated as a ByteArray).

Example, I have a moving car (swf animation) running at 40kph. Then I have a button which will change the speed by increments of 40kph. SO basically, whenever I hit the button, the playing car should change speed by the increment. The difficult part is, I already had this working in Adobe Flex but it doesn't change the speed yet. I mean, it only moves by the keyframe interval I set when I created the swf file on flash (which is, to say, 30 frame interval per keyframe).

So in short, I just need to make the speed change depending on how many increments I asked it to change. A colleague told me to use Timer and TimeEvent of Flex but I can't seem to quite get the hang of it since I'm still new to the ActionScript world.

I hope someone can help me. Thanks :)

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

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

发布评论

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

评论(1

静赏你的温柔 2024-09-14 02:00:44

您需要通过代码为汽车设置动画。以下代码将车轮加速到 120 km/h:

private var car:MovieClip;
private var speed:Number; // from 0 to 120

private function enterFrameHandler(event:Event):void
{
    if (speed < 120)
        speed++;

    car.wheel1.rotation += speed;
    car.wheel2.rotation += speed;
}

这个想法是“即时”计算每个新帧的动画参数。

You need to animate the car from the code. The following code speeds up wheels until 120 km/h:

private var car:MovieClip;
private var speed:Number; // from 0 to 120

private function enterFrameHandler(event:Event):void
{
    if (speed < 120)
        speed++;

    car.wheel1.rotation += speed;
    car.wheel2.rotation += speed;
}

The idea is to calculate animation parameters for every new frame "on the fly".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文