Jump to content

How do you move a sprite AND its collision box?


ojn17041991
 Share

Recommended Posts

I have a series of platforms and under a certain condition, I need them all to move to a different position. The new position is not fixed, it depends on the circumstances and the platform's current position. I tried setting platform.x/y and it moves the sprite to the correct position, but the collision box of the sprite seems not to have moved. I tried setting platform.body.position.x/y (body is enabled), but nothing happens; the collision boxes remain in their original position. I want this to be an instant change in position, so velocity (which I believe moves both the sprite and the collision box) won't really work. Could anyone tell me how to move the collision box of a sprite, either WITH the sprite itself, or independently so I can at least align them manually?

EDIT:

I realised I have body.moves set to false, which seems to be causing the synchronisation between the sprites and their collision boxes. The problem I have is that I can't set body.moves to true, because if I do, setting the positional values ONCE just seems to happen on every frame (for whatever reason). There must be a way of setting a one-time positional value with body.moves set to true, but if there is I sure can't find it.

Link to comment
Share on other sites

That should work regardless of body.moves. There are some times (postUpdate–preUpdate) when setting body.position is ineffective and you need to use sprite.reset(x, y) instead. But if the body is never following the sprite, it sounds like something else if wrong.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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