我怎样才能使它永远运行,并将圆无休止地移动到随机位置?
function tweenPosition(circle) { var xPosition = Math.random() * stageWidth var yPosition = Math.random() * stageHeight createjs.Tween.get(circle, {loop: false}).wait(0).to({x: xPosition, y: yPosition}, 1000, createjs.Ease.sineInOut).onComplete(tweenPositionComplete(this, xPosition, yPosition)) } function tweenPositionComplete(circle, x, y) { circle.x = x circle.y = y tweenPosition(this) }
tweenPosition 函数,而不是使用 onComplete 方法,使用 call
tweenPosition
onComplete
call
call (callback, [params], [scope])
对于您的代码:
.call(tweenPositionComplete, [circle, xPosition, yPosition])
你的孩子看起来像这样:
createjs.Tween .get(circle, {loop:false}) .wait(0) .to({x:xPosition, y:yPosition}, 1000, createjs.Ease.sineInOut) .call(tweenPositionComplete, [circle, xPosition, yPosition]);
在里面 this fiddle
另请参见 : Tween Class (TweenJS API)