我写了这个东西,它随机显示小星星图形,在屏幕上补间,然后删除它们。我遇到了一个问题,虽然可能在 10 秒后,一些星星在补间中间冻结在适当的位置,然后就呆在那里。
这是我的代码:
// Create Random Variables.
var xPosition:int;
var yPosition:int;
// Animate Stars.
function stars ():void {
//Defines random starting position for stars.
xPosition = Math.floor(Math.random()*(540))+5;
yPosition = Math.floor(Math.random()*(2))+5;
//Add and position stars.
var newStar:star = new star();
newStar.x = xPosition;
newStar.y = yPosition;
addChild(newStar);
//Tween stars.
var tweenStar:Tween = new Tween(newStar, "y", None.easeOut, yPosition, stage.stageHeight, 4, true);
//Event listener checks star tween.
tweenStar.addEventListener(TweenEvent.MOTION_FINISH, removeStar);
//Remove stars when tween is complete.
function removeStar(e:TweenEvent):void {
removeChild(newStar);
tweenStar.removeEventListener(TweenEvent.MOTION_FINISH, removeStar);
}
}