ReferncePoint for Sprites and physics bodies

I created some physics bodies from sprites. It appears that collisions occur up and to the left of where the body appears on the screen. I’m guessing this is a problem with the reference points.

Viewing in hybrid mode the debug drawing appears over the art but the physics body is still up and to the right.

Not sure what to do here. Is it possible to offset the physics object? Not sure bodies have reference points.

Sprites with physics objects open up a lot of great possibilities. While also keeping the memory footprint small. [import]uid: 98652 topic_id: 19784 reply_id: 319784[/import]

After some experimentation, I find that setting the shape of the box offsets the physics body to the correct location. But, the debug outlines are not in the correct location!

I used the following to offset the shape of the box.

shape={ 0, 0, 32, 0, 32, 32, 0, 32 } [import]uid: 98652 topic_id: 19784 reply_id: 76711[/import]

Sorry, is this solved now? If not can you put up a sample we could check out, please?

Peach :slight_smile: [import]uid: 52491 topic_id: 19784 reply_id: 76865[/import]

Thanks for the reply. The solution I posted above seems to work, but the debug outline seems to be offset by half the height and width down and to the right. [import]uid: 98652 topic_id: 19784 reply_id: 76900[/import]

Ah yes, the center - I believe currently that may be unavoidable, although a post in feature requests could be a good idea?

Peach :slight_smile: [import]uid: 52491 topic_id: 19784 reply_id: 76922[/import]

I am just starting out with corona, and I’m having a very similar problem. I am attempting to generate a polygon and then attach a physical body to it. For some reason my body is offset approximately 100 pixels in the negative y direction and I have no idea why!

here is the code I have written:

local star = display.newLine(0,-110, 27,-35)
star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,16, -105,-35, -27,-35, 0,-110 )
star:setColor( 255, 102, 102, 255 )
star.width = 8
starcenterShape = {27,-35, 43,16, 0,45, -43,16, -27,-35}
tri1Shape = {-27,-35, 0,-110, 27,-35}
tri2Shape = {27,-35, 105,-35, 43,16}
tri3Shape = {43,16, 65,90, 0,45}
tri4Shape = {0,45, -65,90, -43,16}
tri5Shape = {-43,16, -105,-35, -27,-35}

physics.addBody( star, “dynamic”,
{bounce = .9 , shape = starcenterShape},
{bounce = .9 , shape = tri1Shape},
{bounce = .9 , shape = tri2Shape},
{bounce = .5 , shape = tri3Shape},
{bounce = .9 , shape = tri4Shape},
{bounce = .9 , shape = tri5Shape}
)

star.xOrigin = 240
star.yOrigin = 400

Is there any way to fix this without manually editing all of the y values in my bodies?

Thanks! [import]uid: 116805 topic_id: 19784 reply_id: 79844[/import]

try adding:

[lua]-- center the star in the middle of the display:

star.x = display.contentWidth*0.5
star.y = display.contentHeight*0.5[/lua]
[import]uid: 89165 topic_id: 19784 reply_id: 79876[/import]