本文介绍了在数组中移动对象,从而在ActionScript中产生体育场波效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想移动阵列中的所有对象以产生体育场波效果.
I want to move all objects in an array producing a stadium wave effect.
我想根据对象在舞台上的y值移动对象.我所有的方块大小均为50x50.我要向上移动然后向下移动.下面是我的代码:
I want to move the objects based on their y-value on the stage. All my squares are of 50x50 in size. I want to move them up then move them down. Below is my code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
var t1:Timer = new Timer(100, 0);
var index:int = 0;
t1.addEventListener(TimerEvent.TIMER, ping);
t1.start();
var array:Array = new Array();
addToArray();
function addToArray():void {
for(var i=0; i<10; i++) {
array[i] = new Sq();
array[i].x = i*50 + 50;
array[i].y = 100;
addChild(array[i]);
}
}
function ping(e:TimerEvent) {
if(index < array.length){
moveUp(array[index]);
index ++;
}
}
function moveUp(sq:Sq):void{
var tweenRight:Tween = new Tween(sq,"y",None.easeOut, sq.y, sq.y - 50, 1, true);
tweenRight.addEventListener(TweenEvent.MOTION_FINISH, moveDown);
}
function moveDown(e:TweenEvent):void {
//what to put here?
//or this is not the right way to do this?
}
推荐答案
您需要在moveDown函数中获取补间的对象并应用补间动画(增加y).
You need to grab the tweened object in moveDown function and apply motion tween (increase y).
function moveDown(e:TweenEvent):void {
var sq:Sq = Sq(e.target.obj);
var tweenDown:Tween = new Tween(sq,"y",None.easeOut, sq.y, sq.y + 50, 1, true);
if (Sq(e.target.obj) === array[array.length - 1]) {
trace("this is the last tween down");
tweenDown.addEventListener(TweenEvent.MOTION_FINISH, lastTweenFinish);
}
}
function lastTweenFinish(e:TweenEvent):void {
trace("DONE");
}
还有另一件事,为什么要在moveUp功能中使用计时器t2.
One more thing why are you using Timer t2 in moveUp function.
这篇关于在数组中移动对象,从而在ActionScript中产生体育场波效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!