Problems with object.anchorX/Y together with graphics.newOutline

Hi there!

I’ve been experimenting with graphics.newOutline and it works quite well, one issue I get though is when the anchor point of the actual image is different than the default. No matter what I do here the outline will not follow and rather stick where it would if the image anchor points would be default. [EDIT] I’m using the 2014.2176 daily build.

The code used in picture_1:

local fgFile = "img/lvl\_a.png" local foregroundOutline = graphics.newOutline( 2, fgFile) local foreground = display.newImage(fgFile) foreground.x = cw\*0.5; foreground.y = ch physics.addBody ( foreground, "kinematic", { outline=foregroundOutline, friction=0.3} )

The code used in picture_2:

local fgFile = "img/lvl\_a.png" local foregroundOutline = graphics.newOutline( 2, fgFile) local foreground = display.newImage(fgFile) foreground.anchorY = 1; foreground.x = cw\*0.5; foreground.y = ch physics.addBody ( foreground, "kinematic", { outline=foregroundOutline, friction=0.3} )

I tried adding an anchor point to the outline aswell, but to no avail obviously as it’s not supposed to work that way. I suppose this is a bug, should I file a report on it?

Hi @Nerolyn,

What happens if you gather the outline, create the physics body, and then afterward change the anchor point and position it on screen? Same result?

Brent

Hi Brent,
 

I tried what you said but had the same results as in picture_2, code (for verification):
 

local fgFile = "img/lvl\_a.png" local foregroundOutline = graphics.newOutline( 2, fgFile) local foreground = display.newImage(fgFile) physics.addBody ( foreground, "kinematic", { outline=foregroundOutline, friction=0.3} ) foreground.anchorY = 1; foreground.x = cw\*0.5; foreground.y = ch

Hi @Nerolyn,

I can’t remember the exact rules, but I don’t think offset anchors play nicely with physics objects in general. Could you just align this object by its center point, like this?

[lua]

local fgFile = “img/lvl_a.png”

local foregroundOutline = graphics.newOutline( 2, fgFile)

local foreground = display.newImage( fgFile )

physics.addBody ( foreground, “kinematic”, { outline=foregroundOutline, friction=0.3} )

foreground.x = cw*0.5;

foreground.y = ch-(foreground.height*0.5)

[/lua]

Hi,

Thanks Brent. I was afraid that I would have to go with that solution in the end, but it’s better than nothing.

Thank you for the help!

Hi @Nerolyn,

What happens if you gather the outline, create the physics body, and then afterward change the anchor point and position it on screen? Same result?

Brent

Hi Brent,
 

I tried what you said but had the same results as in picture_2, code (for verification):
 

local fgFile = "img/lvl\_a.png" local foregroundOutline = graphics.newOutline( 2, fgFile) local foreground = display.newImage(fgFile) physics.addBody ( foreground, "kinematic", { outline=foregroundOutline, friction=0.3} ) foreground.anchorY = 1; foreground.x = cw\*0.5; foreground.y = ch

Hi @Nerolyn,

I can’t remember the exact rules, but I don’t think offset anchors play nicely with physics objects in general. Could you just align this object by its center point, like this?

[lua]

local fgFile = “img/lvl_a.png”

local foregroundOutline = graphics.newOutline( 2, fgFile)

local foreground = display.newImage( fgFile )

physics.addBody ( foreground, “kinematic”, { outline=foregroundOutline, friction=0.3} )

foreground.x = cw*0.5;

foreground.y = ch-(foreground.height*0.5)

[/lua]

Hi,

Thanks Brent. I was afraid that I would have to go with that solution in the end, but it’s better than nothing.

Thank you for the help!

Hi ill the problem be fixed? I changed the default anchor for my app with display,setDefault(“anchorX”,0) and want it to continue that way.
Is there a way to change the anchor point without having problems with graphics.newOutline!?

ty in advance
best regards

Hi ill the problem be fixed? I changed the default anchor for my app with display,setDefault(“anchorX”,0) and want it to continue that way.
Is there a way to change the anchor point without having problems with graphics.newOutline!?

ty in advance
best regards