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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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