valueerror Posted August 20, 2014 Share Posted August 20, 2014 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.5but 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 More sharing options...
schteppe Posted August 21, 2014 Share Posted August 21, 2014 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 More sharing options...
valueerror Posted August 21, 2014 Author Share Posted August 21, 2014 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 More sharing options...
valueerror Posted August 21, 2014 Author Share Posted August 21, 2014 that's the phaser code for it game.physics.p2.enable(iceblock,false);iceblock.body.x+=iceblock.width/2;iceblock.body.y+=iceblock.height/2; Link to comment Share on other sites More sharing options...
Recommended Posts