探索Tweenjs。我只想在舞台上随意转几圈。我知道所有的推文都是“确定性的”,这意味着它使用了预先计算出来的速度值。所以我有两个函数可以互相调用。当吐温完成时,调用第二个函数。不幸的是,我收到了一个调用堆栈溢出错误。
HOw,我可以让这个永远运行,并无休止地移动圆圈随机位置?
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)
}发布于 2017-07-10 13:52:35
在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]); 在这把小提琴中,您可以看到它的作用。
也见:中间类(TweenJS API)
https://stackoverflow.com/questions/45001236
复制相似问题