Change position of collision circle?

Hi,

As you can see in the following image, I am not happy with the default physics circle’s position. I want to move it a little bit, How can i change it’s position???

radius.jpg

You cannot. Circle is centered at image center.

Then how do i change the center of the image, and will it change the circle’s position?

Thanks

You just make image in such way that center is in point you want circle to be. For eg. add some alpha padding.

The easiest way to to do something like this:

local function createPlayerLocation() player0 = hero.createHero() player0:setReferencePoint(display.CenterReferencePoint) player0.hitBox = display.newRect(0,0,26,16) physics.addBody(player0.hitBox, { density = 60.0, friction = 0.3, bounce = 0 }) player0.hitBox:setFillColor(0,0,0,0) player0.hitBox..x = 100 player0.hitBox..y = 200 player0.x = player0.hitBox.x player0.y = player0.hitBox.y end createPlayerLocation() -- more code for your app -- Here's your Runtime code: local function movingTime() -- Your regular Runtime code player0.x = player0.hitBox.x player0.y = player0.hitBox.y end Runtime:addEventListener("enterFrame", movingTime)

This will pin your character sprite to your physics object. 

Hi @coolromin,

You may also opt to just draw a polygon “circle” using the shape method, which could be drawn “non-center” if you wish. This could be, at most, an 8 sided shape (so, an octagon), but you could draw two halves side-by-side for a more accurate circle. But, it looks like you could go even more detailed regardless, and trace these figures with a more accurate shape than a circle.

See the physics body guide here:

http://docs.coronalabs.com/guide/physics/physicsBodies/index.html

Best regards,

Brent

You cannot. Circle is centered at image center.

Then how do i change the center of the image, and will it change the circle’s position?

Thanks

You just make image in such way that center is in point you want circle to be. For eg. add some alpha padding.

The easiest way to to do something like this:

local function createPlayerLocation() player0 = hero.createHero() player0:setReferencePoint(display.CenterReferencePoint) player0.hitBox = display.newRect(0,0,26,16) physics.addBody(player0.hitBox, { density = 60.0, friction = 0.3, bounce = 0 }) player0.hitBox:setFillColor(0,0,0,0) player0.hitBox..x = 100 player0.hitBox..y = 200 player0.x = player0.hitBox.x player0.y = player0.hitBox.y end createPlayerLocation() -- more code for your app -- Here's your Runtime code: local function movingTime() -- Your regular Runtime code player0.x = player0.hitBox.x player0.y = player0.hitBox.y end Runtime:addEventListener("enterFrame", movingTime)

This will pin your character sprite to your physics object. 

Hi @coolromin,

You may also opt to just draw a polygon “circle” using the shape method, which could be drawn “non-center” if you wish. This could be, at most, an 8 sided shape (so, an octagon), but you could draw two halves side-by-side for a more accurate circle. But, it looks like you could go even more detailed regardless, and trace these figures with a more accurate shape than a circle.

See the physics body guide here:

http://docs.coronalabs.com/guide/physics/physicsBodies/index.html

Best regards,

Brent