degressor Posted February 23, 2016 Share Posted February 23, 2016 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 More sharing options...
lukaMis Posted February 23, 2016 Share Posted February 23, 2016 How can path be predefined and dynamic? Mybe write what are you trying to do and post whole code sample. Link to comment Share on other sites More sharing options...
AzraelTycka Posted February 23, 2016 Share Posted February 23, 2016 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 More sharing options...
degressor Posted February 24, 2016 Author Share Posted February 24, 2016 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 More sharing options...
iKest Posted February 24, 2016 Share Posted February 24, 2016 Can be used tweens whith angularVelocity and velocityFromAngle... http://phaser.io/examples/v2/arcade-physics/angular-velocity Link to comment Share on other sites More sharing options...
AzraelTycka Posted February 24, 2016 Share Posted February 24, 2016 I don't know how rotation is done but would try either false, null or how about just giving a zero angle? Link to comment Share on other sites More sharing options...
lukaMis Posted February 25, 2016 Share Posted February 25, 2016 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 More sharing options...
Recommended Posts