Jump to content

enabling p2 physics moves the sprite to the left and top exactly half the sprite size


valueerror
 Share

Recommended Posts

i know this is because the anchor of a normal sprite is at 0,0 and p2 physics sets the anchor to 0.5,0.5

but this sucks !

 

how can i avoid this moving around of my sprites just because they get a physics body..

 

 

in my special case i create sprites from objects (tiled object layer)

so i position my objects precisely in tiled just to see every object repositioned when physics is enabled..

 

do i really have to correct x and y of every sprite after enabling physics?

Link to comment
Share on other sites

Set the anchor of the sprite to (0.5,0.5), then immediately set the position of the physics body to (spriteX-spriteSizeX/2, spriteY-spriteSizeY/2). No one will even notice you moved anything. (Note: i might have gotten the signs wrong)

I don't think the position conventions are going to change for a while. Physics bodies will always have their center of mass in the center. If you move it inside the physics body, you'll get weird results. And for sprites, it's easier to position by corner.

Link to comment
Share on other sites

thx schteppe.. that's what i've been doing..      i just thought that a few releases ago phaser corrected the position of the sprite automatically so enabling physics and changing the anchor does not reposition the sprite..  whatever..  maybe to much programming and to little sleep :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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