Jump to content

Move along predefined path with Phaser


degressor
 Share

Recommended Posts

Hallo, I need to move and rotate a player by a predefined path. Like: [stepForward, turnLeft, stepForward, turnLeft, stepForward, stepForward, stepForward, ...]

The problem is, the path is dynamic and depends on user input.

I tried to put the coordinates and agles in arrays and  do something like tween.to({x:[...], y:[...], angle:[...], 5000, Phaser.Easing.Linear.None, true); But in this case I got problems with rotation.

I don't know how to chain dynamicly or use several .to call.  Any ideas?

Link to comment
Share on other sites

Hello,

you can use onComplete just move your object with tween to first location and then in onComplete reuse the old tween/create a new tween and send your object to a new location and repeat this until you have no more directions left.

PS: Not sure what problem with rotation means, just rotate it by the angle you have - as far as I guessed what yo uare doing - or what kind of path movement you are building.

Link to comment
Share on other sites

14 hours ago, lukaMis said:

How can path be predefined and dynamic? Mybe write what are you trying to do and post whole code sample.

Sorry, I mean it's predefined before the runtime, but every run different so I can't hardcode it.

 

13 hours ago, AzraelTycka said:

Hello,

you can use onComplete just move your object with tween to first location and then in onComplete reuse the old tween/create a new tween and send your object to a new location and repeat this until you have no more directions left.

PS: Not sure what problem with rotation means, just rotate it by the angle you have - as far as I guessed what yo uare doing - or what kind of path movement you are building.

I solved the problem with onComplete. Thx.

The problem with rotation was, I need to rotate only on some points. [noRotation, noRotation, 90, noRotation]. So I dind't know what to put to the points with no rotation needed? null?

 

Link to comment
Share on other sites

You can just not tween rotation in some tweens or if you must you can save and pass it in tween: 

var _angle = this.mySprite.angle;
this.mySprite.moveTween = this.game.add.tween(this.mySprite).to( { x: some_value, y: some_value, rotation: _angle }, 1000, Phaser.Easing.Sinusoidal.InOut, true);

or you can save it as property of your sprite and tween it
 

this.mySprite.myNewAngle = 90;
this.mySprite.moveTween = this.game.add.tween(this.mySprite).to( { x: some_value, y: some_value, rotation: this.mySprite.myNewAngle }, 1000, Phaser.Easing.Sinusoidal.InOut, true);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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