Hey,
First, I think this is an issue with the physics body and anchors, the documentation for addBody states that;
If you change the anchorX or anchorY property of a display object before adding a physics body, the body will be positioned properly relative to the adjusted anchor. However, you should not change the anchor point after adding the body or the object and body will be misaligned.
This seems to be true for regular images, but with @2x or @4 the image obeys the anchors but the physics body doesn’t seem to.
I played around with when I changed the anchorX = 0 and anchorY = 0 lines.
I discovered that if I add the lines before I add the physics bodies then (as it should be);
@1x = perfect
@2x = off by 1/2 width and height of object
@4x = off by 1 1/2 width and height of object
If I add the lines after I create the physics bodies then
@1x = off by 1/2 width and height of object
@2x = off by width and height of object
@4x = off by 2x width and height of object
The differences here tell me the physics engine is trying to do something, it’s just not working correctly. It would be interesting to get someone elses take on this.
Anyway, I came up with the following solution, it is not elegant but it works. In case anyone else has a similar issue…
In my setting file I have the following;
local scale = display.imageSuffix if scale == "@4x" then common.scaleFactor = 4 elseif scale == "@2x" then common.scaleFactor = 2 else common.scaleFactor = 1 end
I then call the following after I define the physics outline, I pass over the outline and the physicsObject (I could just pass over the width).
public.moveOutLine = function (thisBody, physicsObject) local modifiedShape = {} for k=1, #thisBody - 1, 2 do local pairX = thisBody[k] local pairY = thisBody[k+1] -- aPiece.width modifiedShape[k] = pairX + (physicsObject.width /2) \* common.scaleFactor modifiedShape[k+1] = pairY - (physicsObject.height /2) \* common.scaleFactor end return modifiedShape end
I hope this helps someone.
Craig