Sign in to follow this  
degressor

Move along predefined path with Phaser

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?

Share this post


Link to post
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.

Share this post


Link to post
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?

 

Share this post


Link to post
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);

 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.