代码之家  ›  专栏  ›  技术社区  ›  user3055135

重复tween中的Tweenjs随机值

  •  0
  • user3055135  · 技术社区  · 8 年前

    我怎样才能使它永远运行,并将圆无休止地移动到随机位置?

    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)
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   cristiancajiaos    8 年前

    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)

    推荐文章