Jump to content

Ship starts flying on changing y position


kray
 Share

Recommended Posts

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

  • 1 month later...

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

 Share

  • Recently Browsing   0 members

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