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.