kray Posted March 26, 2015 Share Posted March 26, 2015 In my code, after checking a condition, I changed the y position of my sprite (a ship). When I do that, the ship does not stay at that position, instead it flies off the screen. The code: answer: function(sprite) { if(sprite.name == "have") { this.bgMusic.stop(); this.bgMusic.loop = false; this.cheer = this.game.add.audio('cheer'); this.cheer.play(); this.ship.y=340; this.text.y=420;}I tried adding this.ship.body.velocity.y=0;this.text.body.velocity.y=0;but it has no effect. What seems to be the issue? Link to comment Share on other sites More sharing options...
kray Posted March 26, 2015 Author Share Posted March 26, 2015 I understood the issue. It is because answer is called only when the condition becomes true and then the function exits. How do make the control sty within the function? Link to comment Share on other sites More sharing options...
JazzAceman Posted March 27, 2015 Share Posted March 27, 2015 Does any gravitation effects your sprite? Or is the sprite-body's acceleration.y value setted > 0? Link to comment Share on other sites More sharing options...
adamsko Posted May 2, 2015 Share Posted May 2, 2015 from http://phaser.io/docs/2.3.0/Phaser.Physics.Arcade.Body.html#moves If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never actually changes, then you should set Body.moves = false. Otherwise it will most likely fly It sounds exactly as your problem. You're having physics system on, plus you're changing sprite's position and physics system is (probably) using this new posistion for physics calculations. Hence suprising sprite's movement. Link to comment Share on other sites More sharing options...
adamsko Posted May 6, 2015 Share Posted May 6, 2015 I asked similar question here: http://www.html5gamedevs.com/topic/14248-sprite-physics-changing-sprites-coordinates/ Link to comment Share on other sites More sharing options...
Recommended Posts