newLine anchor issues

Hello,

I’m having issues with Line objects where anchorX and anchorY do not seem to be working properly. Let’s say I have the following code:

local myRect = display.newRect(0,0,100,100); myRect.strokeWidth = 2; myRect:setStrokeColor(0,0,1); myRect.anchorX = 0.5; myRect.anchorY = 0.5; myRect.x = display.contentWidth \* 0.5; myRect.y = display.contentHeight \* 0.5; localGroup:insert(myRect); local myLine = display.newLine(0,0,100,100); myLine.strokeWidth = 2; myLine:setStrokeColor(1,0,0); myLine.anchorX = 0.5; myLine.anchorY = 0.5; myLine.x = display.contentWidth \* 0.5; myLine.y = display.contentHeight \* 0.5; localGroup:insert(myLine);

I assumed that myLine would be drawn from the top left corner of myRect to the bottom right corner of myRect.

Instead, the top left corner of myLine starts at the center of myRect and the bottom right corner of myLine is outside myRect (50,50) away from from the bottom right corner of myRect. In other words, it’s in the same position as if I had myLine.anchorX = 0 and myLine.anchorY = 0.

What I find odd is that this ONLY happens when anchorX and/or anchorY is 0.5. With any other anchorX and anchorY aside from 0.5, the line seems to be drawn in the correct position. For example, if I make the anchors 0.49 or 0.51, the line is almost centered in myRect. Additionally, when anchors equal 0, 1, .25 and .75 there doesn’t seem to be a problem.

Has anyone else had this odd issue? 

Thank you for your time and have a nice day.

I seem to be having a similar problem except that putting the anchor close to 0.5 doesn’t help. The line (with multiple appended points) goes completely out of whack unless it is never touched. This is rather inconvenient as now I can’t use display:setDefault(…) as it messes the lines up.

@philreeder Thanks for the extra info.

Is anyone else out there able to replicate this issue? Or the opposite, is there anyone out there who does not get this issue? Would be helpful to know in either case.

Thank you for your time and have a nice day.

BUMP

I can confirm that anchor points DO NOT work as advertised on line objects (at least as of latest public build 2013.2100).  The ONLY values that seem to have ANY effect are the exact values 0 and 1 (for left/right, top/bottom alignment).  Fractional values, in particular 0.5, do not center, and instead seem to have the odd effect of setting the anchor to the starting point of the line.  (that is, if you then set x/y with anchor 0.5,0.5 the first point of the line is positioned at that x/y)

-- create a circle that is centered: local knownCenter = display.newCircle( display.contentCenterX, display.contentCenterY, 5 ) knownCenter:setFillColor(0,1,0) -- create a line that is definately not centered (not even on screen): local line = display.newLine( 1100, 100, 1200, 80 ) line:setStrokeColor(1,0,0) -- sanity checks: print("line cwidth/cheight = " .. line.contentWidth .. ", " .. line.contentHeight) print("line anchorX/anchorY = " .. line.anchorX .. ", " .. line.anchorY) -- already 0.5,0.5, but set it again if you want (makes no difference): --line.anchorX, line.anchorY = 0.5,0.5 -- position line at center: line.x, line.y = display.contentCenterX, display.contentCenterY -- oops, didn't work

I seem to be having a similar problem except that putting the anchor close to 0.5 doesn’t help. The line (with multiple appended points) goes completely out of whack unless it is never touched. This is rather inconvenient as now I can’t use display:setDefault(…) as it messes the lines up.

@philreeder Thanks for the extra info.

Is anyone else out there able to replicate this issue? Or the opposite, is there anyone out there who does not get this issue? Would be helpful to know in either case.

Thank you for your time and have a nice day.

Thanks for reporting this issue.

I’ve added a new boolean property to LineObjects called “anchorSegments”. This property will be available in tomorrow’s daily build.

This property controls whether LineObjects should take anchors into account. The default value is false.

Let me know if this fixes your problem.

BUMP

I can confirm that anchor points DO NOT work as advertised on line objects (at least as of latest public build 2013.2100).  The ONLY values that seem to have ANY effect are the exact values 0 and 1 (for left/right, top/bottom alignment).  Fractional values, in particular 0.5, do not center, and instead seem to have the odd effect of setting the anchor to the starting point of the line.  (that is, if you then set x/y with anchor 0.5,0.5 the first point of the line is positioned at that x/y)

-- create a circle that is centered: local knownCenter = display.newCircle( display.contentCenterX, display.contentCenterY, 5 ) knownCenter:setFillColor(0,1,0) -- create a line that is definately not centered (not even on screen): local line = display.newLine( 1100, 100, 1200, 80 ) line:setStrokeColor(1,0,0) -- sanity checks: print("line cwidth/cheight = " .. line.contentWidth .. ", " .. line.contentHeight) print("line anchorX/anchorY = " .. line.anchorX .. ", " .. line.anchorY) -- already 0.5,0.5, but set it again if you want (makes no difference): --line.anchorX, line.anchorY = 0.5,0.5 -- position line at center: line.x, line.y = display.contentCenterX, display.contentCenterY -- oops, didn't work

Thanks for reporting this issue.

I’ve added a new boolean property to LineObjects called “anchorSegments”. This property will be available in tomorrow’s daily build.

This property controls whether LineObjects should take anchors into account. The default value is false.

Let me know if this fixes your problem.

Hi Albert,

  Just ran into this myself.  Would suggest anchorSegments be added to the gotchas one

http://docs.coronalabs.com/api/library/display/newLine.html

Hi Albert,

  Just ran into this myself.  Would suggest anchorSegments be added to the gotchas one

http://docs.coronalabs.com/api/library/display/newLine.html