Actionscript 3 检测阵列中的最后一项何时停止
我有一个精灵数组,我通过增加它们的rotationX属性来设置它的动画。我想要的是,一旦数组中的最后一个项完成循环,它们就会全部消失。问题是它们的旋转速度是由一个随机函数产生的,所以我不能只到数组的末尾去寻找最后一个。每一次都是不同的 所以我有一组精灵:Actionscript 3 检测阵列中的最后一项何时停止,actionscript-3,algorithm,Actionscript 3,Algorithm,我有一个精灵数组,我通过增加它们的rotationX属性来设置它的动画。我想要的是,一旦数组中的最后一个项完成循环,它们就会全部消失。问题是它们的旋转速度是由一个随机函数产生的,所以我不能只到数组的末尾去寻找最后一个。每一次都是不同的 所以我有一组精灵: for(var i:int=0; i<arrSprites.length; i++) { addChild(arrSprites[i]) ; } 我的经纪人: private function loop(e:Event):
for(var i:int=0; i<arrSprites.length; i++)
{
addChild(arrSprites[i]) ;
}
我的经纪人:
private function loop(e:Event):void
{
for(var i:int=0; i<arrSprites.length; i++)
{
var currentSprite:Sprite = arrSprites[i];
if(currentSprite.rotationX < 361) //this will detect the first one
//to finish but I want the last
{
currentSprite.rotationX += arrSprites[i].speed; //random speed
}
else
{
deleteTheSprites(); //removes all sprites and does other stuff
}
}
}
私有函数循环(e:事件):无效
{
对于(var i:int=0;iprivate函数循环(e:Event):void
{
var finished:int=0;//将计算完成的精灵数
对于每个(var电流:arrSprites中的精灵)
{
如果(current.rotationX<361)current.rotationX+=当前速度;
else if(++finished==arrSprites.length)deletetetesprites();//仅当所有精灵都已完成时执行
}
}
精彩绝伦,是的,优雅。谢谢。
private function loop(e:Event):void
{
for(var i:int=0; i<arrSprites.length; i++)
{
var currentSprite:Sprite = arrSprites[i];
if(currentSprite.rotationX < 361) //this will detect the first one
//to finish but I want the last
{
currentSprite.rotationX += arrSprites[i].speed; //random speed
}
else
{
deleteTheSprites(); //removes all sprites and does other stuff
}
}
}
private function loop(e:Event):void
{
var finished : int = 0; // will count the number of sprites finished
for each (var current:Sprite in arrSprites)
{
if (current.rotationX < 361) current.rotationX += current.speed;
else if (++finished == arrSprites.length) deleteTheSprites(); // executes only if all sprites have finished
}
}