Ship starts flying on changing y position

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( == "have")   {       this.bgMusic.stop();       this.bgMusic.loop = false;              this.cheer ='cheer');;              this.ship.y=340;       this.text.y=420;}

I tried adding 


but it has no effect. What seems to be the issue?




Share this post

Link to post
Share on other sites

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?

Share this post

Link to post
Share on other sites



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.

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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.