Jump to content

Create dynamically tweens for path


Recommended Posts

Hello everyone,


I'm actually working on a Phaser Game.

I'm already done a pathfinding for getting the path my soldier should take.

Now I would like to make tweens for it and create a chained tween with each tile of the path.


Every infos I found don't speak about creating a tween object.

Like it we could add new steps to it and after assign it to a sprite for example and play it.


Sorry for my english... (FrenchStyle ^^)


github : GreG28

Link to comment
Share on other sites


chaining tweens is simple

//some coordinatesvar steps = [	{x: 100, y: 100},	{x: 100, y: 150},	{x: 100, y: 200},	{x: 150, y: 200},	{x: 200, y: 200}];//createthis.chainedTween = this.add.tween(this.mySprite);//attachfor (var i = 0; i < steps.length; i++) {	this.chainedTween.to({ x: steps[i].x,  y: steps[i].y }, 500, "Quad.easeOut");}this.chainedTween.start();

or you can use the chain method

var tweenA = this.add.tween(this.mySprite).to({x: 100, y: 250}, 1000);var tweenB = this.add.tween(this.mySprite).to({x: 250, y: 150}, 1000);var tweenC = this.add.tween(this.mySprite).to({x: 350, y: 200}, 1000);tweenA.chain(tweenB, tweenC);tweenA.start();
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.

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.


  • Recently Browsing   0 members

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