Bug in anchorY and Y?

@Brent,

How would you implement the same code for two circles instead of two squares?  I’m having the same problem aligning two circles; the anchorX and anchorY keep displaying as if they were 0.5.

Thanks,

Jonathan

Hi @sharp100,

Can you post a little code? Circles will have the same anchor points as if imaginary (square) boundaries surrounded them. If you want to align the edges of circles that are different sizes and which don’t share the same horizontal or vertical axis, then you’ll need to calculate the math for that (which should be easy enough to find online; I just don’t recall the formula off hand).

Brent

OK , here is a working sample of anchor points with circles.  I started tracking all of the anchor points with little green circles and it made me realize that it was easier to just keep all the anchors centered (0.5) to avoid confusion.

[lua]

– radii of circles

local redRad = 100

local blueRad = 50

local greenRad = 10

local redBlueRad = redRad + blueRad  – I used this as the hypotenuse of an imaginary circle whose radius was the distance between the centers of the the red and blue circles (green center point circles)

–put a RED circle on the screen

local red = display.newCircle( 0, 0, redRad )

red:setFillColor(1,0,0)

red.anchorX = 0.5              – to keep it simple, I made all anchor points centered (0.5)

red.anchorY = 0.5

red.x = display.contentWidth - redRad

red.y = 0 + redRad

–put a BLUE circle on the screen

local blue = display.newCircle( 0, 0, blueRad )

blue:setFillColor(0,0,1)

blue.anchorX = 0.5

blue.anchorY = 0.5

blue.x = red.x - math.cos( 0.785 ) * redBlueRad  – 45 degrees translated into radians = 0.785

blue.y = red.y + math.sin( 0.785 ) * redBlueRad  – redBlueRad is the imaginary hypotenuse red and blue centers

–put a GREEN circle on the screen as a center point

local green = display.newCircle( 0, 0, greenRad )

green:setFillColor(0,1,0)

green.anchorX = .5

green.anchorY = .5

green.x = red.x

green.y = red.y

–put a GREEN circle on the screen as a center point

local green2 = display.newCircle( 0, 0, greenRad )

green2:setFillColor(0,1,0)

green2.anchorX = .5

green2.anchorY = .5

green2.x = blue.x

green2.y = blue.y

[/lua]

Jonathan