FLASH/AS3:一种通过弹跳效果将影片剪辑从一个位置移动到另一个位置的方法
我想要一个类似大静态图像的东西,你可以通过单击按钮来移动它,并具有“弹跳”效果。移动到特定位置的按钮很好,但允许您在一定限制内自由移动它的附加按钮更好。
我在很久以前的某个地方找到了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有完整的库包可以用一行代码处理整个动画链。
Tweener
TweenLite
There are entire library packages that can handle the entire animation chain with a single line of code.
Tweener
TweenLite