How to make the physical model repeat the movement for the sprite?
Link to the video where the problem is clearly shown:
P.S. The code is in standard patterns called - AnchorPoints
How to make the physical model repeat the movement for the sprite?
Link to the video where the problem is clearly shown:
P.S. The code is in standard patterns called - AnchorPoints
Physics objects don’t really play nice with display groups.
You are experiencing that issue because you are adjusting the display object’s anchor point after it has been created. The physics body doesn’t respond to changes in the anchor point after it has been created.
All you need to do is destroy the physics body before you change the anchor and then recreate it. Add the following lines of code to lines 50 and 60 and it’ll work:
physics.removeBody( logo ) – line 50
physics.addBody( logo ) – line 60
You can turn the body off by setting isBodyActive = false and then back to true later. This is not quite the same so your mileage may vary and both solutions deserve at least some trial and error.
I don’ think that isBodyActive works here as it doesn’t affect the anchor of the physics body at all. The only way to reasonably “adjust” the anchor of a physics body is to delete the current body and create a new one.
Thank you all for your help !!! You helped me a lot.
Physics objects don’t really play nice with display groups.
You are experiencing that issue because you are adjusting the display object’s anchor point after it has been created. The physics body doesn’t respond to changes in the anchor point after it has been created.
All you need to do is destroy the physics body before you change the anchor and then recreate it. Add the following lines of code to lines 50 and 60 and it’ll work:
physics.removeBody( logo ) – line 50
physics.addBody( logo ) – line 60
You can turn the body off by setting isBodyActive = false and then back to true later. This is not quite the same so your mileage may vary and both solutions deserve at least some trial and error.
I don’ think that isBodyActive works here as it doesn’t affect the anchor of the physics body at all. The only way to reasonably “adjust” the anchor of a physics body is to delete the current body and create a new one.
Thank you all for your help !!! You helped me a lot.