adamsko Posted May 2, 2015 Share Posted May 2, 2015 Hello. I've noticed that many people have a similar problem.If sprite has physics enabled: how to change its position without interfering with physics system?It's a famous 'fly off the screen' problem. If position is changed, physics system is using new coordinates to continue its work, hence sprite's surprising behavior.Let's say,that sprite is moving and when it's clicked it should move 100px on the right and then continue its movement), maybe with a different speed. How to achieve that?My solution is:sprite.body.moves = false;object.sprite.x += 100;... and then in game's update() function:function update() { sprite.body.reset(sprite.x, sprite.y); sprite.body.velocity.x = 10; // new velocity sprite.body.moves = true;}I understand, that physics system must be after one update, otherwise switching betweenbody.moves = falseandbody.moves = truewill not have a chance to work. After that sprite is translated 100px in the right, plus it has new velocity.The question is: is there a proper Phaser way to achieve that without splitting this operation on instructions executed before and after update() function? It's seems like a common need and yet it takes that little extra effort to achieve desired effect Arcanorum, drhayes and Aurelijus 3 Link to comment Share on other sites More sharing options...
Aurelijus Posted December 27, 2015 Share Posted December 27, 2015 deleted Link to comment Share on other sites More sharing options...
nobody Posted January 4, 2016 Share Posted January 4, 2016 For me and with Arcade, it's good enough to just make sprite.body.position += 100. Seems to be no need to update sprite position, or wait for the next update() and re-enable the body. Link to comment Share on other sites More sharing options...
Recommended Posts