Jump to content

Tweening to moving object


Jazz
 Share

Recommended Posts

Hello,

 

im trying to tween the camera to the player position like this:

 

this.cameraTween= game.add.tween(game.camera).to({y: (player.y- (game.camera.height /2)), x: (player.x- (game.camera.width /2))}, 500).start()

this.cameraTweenBack.onComplete.add(function () {
game.camera.follow(player);

}, this);

 

this is OK when the player is not moving.

However when the player is moving the follow function will make it snap to the delta it moved during the tween.

chaining tweens dint fix this problem for me

 

 

Link to comment
Share on other sites

Something like this works, but its to jittery

    this.onUpdate = function () {        console.log("x: " + game.camera.x + "y: " + game.camera.y)        game.tweens.remove(this.cameraTweenBack);        if ((game.camera.y - (player.y - (game.camera.height / 2)) < 10) &&            (game.camera.x - (player.x - (game.camera.width / 2)) < 10)) {            console.log("destination reached")            game.camera.follow(player);        }        else {            this.cameraTweenBack = game.add.tween(game.camera).to({                y: (player.y - (game.camera.height / 2)),                x: (player.x - (game.camera.width / 2))            }, 50).start()            this.cameraTweenBack.onUpdateCallback(this.onUpdate, this);        }    }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...