Golen

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. Nice catch!! That solution works well. I'm having a look at the source, and my guess is that the position is only updated in body.preUpdate(), which is called the next frame? Meanwhile, the collision and render is called prior to that. Size is updated immediately in body.setSize(). (I'm slightly annoyed that the body is affected by scale, but not angle. In case I want the sword to alternate directions by flipping the y axis, I have to add calculate additional offset.)
  2. I'm trying to add a collision box to a sword swing. I'm using one sprite for the swing and rotating it 0, 90, 180, 270 degrees, depending on direction. As physics bodies are not affected by their sprite's rotation, I'm using body.setSize(width, height, offsetX, offsetY) to move the collision area depending on direction. Problem: It seems that (width, height) updates earlier than (offsetX, offsetY), or that the new offset is delayed one update. This leads to the hitbox reaching beyond the player's attack range. How can I avoid this? One way to easily test this is by calling sprite.body.setSize( <randomX>, <randomY>, <randomOffsetX>, <randomOffsetY> ). The sprite's angle does not affect this. ^ The collision area updates its size first, and later snaps to its new offset. ^ The sword sprite, 48x48. Red box indicates where the body's collision area should be.