FLASH/AS3:一种通过弹跳效果将影片剪辑从一个位置移动到另一个位置的方法

发布于 2024-09-25 03:06:51 字数 1780 浏览 0 评论 0原文

我想要一个类似大静态图像的东西,你可以通过单击按钮来移动它,并具有“弹跳”效果。移动到特定位置的按钮很好,但允许您在一定限制内自由移动它的附加按钮更好。

我在很久以前的某个地方找到了 Actionscript 1.0 中的一个脚本,但我不知道如何将其更新为 3.0(也不知道是否有教程解释任何类似的效果)。

可移动MovieClip的脚本:

onClipEvent (load) {
    moving = 0;
    x = 0;
    rebote = 0;
    section_actual = 1;
    section_new = 1;
    friction = 0.9;
}
onClipEvent (enterFrame) {
    if (moving == 1)
    {
        if (cambio == 1)
        {
            if (section_actual-section_new<0)
            {
                accel = -2;
            }
            else
            {
                accel = 2;
            }
        }
        cambio = 0;
        section_actual = section_new;
        if (accel == -2)
        {
            if (_x+xvel<=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
        if (accel == 2)
        {
            if (_x+xvel>=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
    }
}

一个按钮的脚本:

on (release) {
    tellTarget ("../")
    {
        moving = 1;
        x = -335;
        rebote = 0;
        section_new = 2;
        cambio = 1;
    }
}

与问题无关,但仍然需要,我需要更新按钮的功能:

on (release) {
    _root.gotoAndStop("TT");
}

I want to have something like a big still image that you can move by clicking buttons—with a "bouncing" effect. Buttons that moves to an specific position are fine, although additional buttons that allow you to move it freely within a certain restriction is even better.

I have an script for it in Actionscript 1.0 I found somewhere eons ago, yet I don't know how to update it for 3.0 (nor if there's a tutorial that explain any similar effect).

The script for the movable MovieClip:

onClipEvent (load) {
    moving = 0;
    x = 0;
    rebote = 0;
    section_actual = 1;
    section_new = 1;
    friction = 0.9;
}
onClipEvent (enterFrame) {
    if (moving == 1)
    {
        if (cambio == 1)
        {
            if (section_actual-section_new<0)
            {
                accel = -2;
            }
            else
            {
                accel = 2;
            }
        }
        cambio = 0;
        section_actual = section_new;
        if (accel == -2)
        {
            if (_x+xvel<=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
        if (accel == 2)
        {
            if (_x+xvel>=x)
            {
                xvel = -xvel;
                _x = x;
                xvel += accel;
                xvel *= friction;
                rebote = 1;
            }
            else
            {
                _x += xvel;
                xvel += accel;
                xvel *= friction;
            }
        }
    }
}

The script for one button:

on (release) {
    tellTarget ("../")
    {
        moving = 1;
        x = -335;
        rebote = 0;
        section_new = 2;
        cambio = 1;
    }
}

Unrelated to the problem but still a need, I need to update the function of a button:

on (release) {
    _root.gotoAndStop("TT");
}

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

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

发布评论

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

评论(1

一绘本一梦想 2024-10-02 03:06:51

有完整的库包可以用一行代码处理整个动画链。

Tweener

TweenLite

There are entire library packages that can handle the entire animation chain with a single line of code.

Tweener

TweenLite

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