(ActionScript) Move objects in an array producing a stadium wave effect

为君一笑 提交于 2019-12-02 18:50:07

问题


I want to move all objects in an array producing a stadium wave effect, how do i do that? 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, please give me advice. Thanks!

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?
}

回答1:


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");
}
One more thing why are you using Timer t2 in moveUp function.

来源:https://stackoverflow.com/questions/2161123/actionscript-move-objects-in-an-array-producing-a-stadium-wave-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!