Drawing a line from Point to Point

I’m working on a drawing game and I built my own function that drawings a rectangle from one point to the next by finding the length between the two points and rotating the rectangle.  

I’m really disappointed though because the rectangles edges are very choppy.  Any ideas?  Thanks

Can you show your drawing code?  And maybe an image of the “choppy” lines. 

Some of the lines aren’t so bad but others are quite jagged.  Maybe its just the simulator though.  Working on getting an Image.


[lua]

width = display.contentWidth

height = display.contentHeight

display.setStatusBar(display.HiddenStatusBar)

configDraw = {15}

drawTable = {}

function startDraw( draw )

    if draw.phase == “began” then

    

    drawTable[1] = display.newCircle(draw.x,draw.y, configDraw[1])

    

    drawTable[1].origX = draw.x

    drawTable[1].origY = draw.y

    

    end

    

    

    if draw.phase == “ended” then

    drawTable[2] = display.newCircle(draw.x,draw.y, configDraw[1])

    drawTable[2]:setFillColor(0,0,255)

    drawTable[2].origX = draw.x

    drawTable[2].origY = draw.y

    

        

        

    

    midPointX = math.abs(drawTable[1].origX+drawTable[2].origX)/2

    midPointY = math.abs(drawTable[1].origY+drawTable[2].origY)/2

    length = 

        math.sqrt(

        math.abs(drawTable[1].origX-drawTable[2].origX)^2 + 

        math.abs(drawTable[1].origY-drawTable[2].origY)^2

                )

                

        deltaX = drawTable[1].origX-drawTable[2].origX – used for calculating angle

        deltaY = drawTable[1].origY-drawTable[2].origY  – used for calculating angle

    angle = math.atan2(deltaY,deltaX)*(180/math.pi) – radian angle converted to degrees using 180/pi

    

    line = display.newRect(999,999,length,15)

    line.x = midPointX

    line.y = midPointY

    line.rotation = angle

    line:setFillColor(100,255,100)

    

    table.remove(drawTable,1)

    table.remove(drawTable,1) --removes both items in table

    

    print("=================================")

        for i =1,#drawTable do

        print(“Drawtable#”…i…"  x="…drawTable[i].origX…"  y="…drawTable[i].origY)

        end

    

    end

end

screen = display.newRect(0,0,width,height)

screen.alpha = 0

screen.isHitTestable = true

screen:addEventListener(“touch”,startDraw)

[/lua]


Hi @DCbball4life,

This is occurring because, at this time, anti-aliasing isn’t supported. In most cases, this is not too noticeable when you have a HD/Retina device and you set a content area that is near or matching the native resolution. However, I understand that some people want this feature; I believe it will be available in the upcoming graphics engine revamp, which is currently in beta testing.

Sincerely,

Brent Sorrentino

Can you show your drawing code?  And maybe an image of the “choppy” lines. 

Some of the lines aren’t so bad but others are quite jagged.  Maybe its just the simulator though.  Working on getting an Image.


[lua]

width = display.contentWidth

height = display.contentHeight

display.setStatusBar(display.HiddenStatusBar)

configDraw = {15}

drawTable = {}

function startDraw( draw )

    if draw.phase == “began” then

    

    drawTable[1] = display.newCircle(draw.x,draw.y, configDraw[1])

    

    drawTable[1].origX = draw.x

    drawTable[1].origY = draw.y

    

    end

    

    

    if draw.phase == “ended” then

    drawTable[2] = display.newCircle(draw.x,draw.y, configDraw[1])

    drawTable[2]:setFillColor(0,0,255)

    drawTable[2].origX = draw.x

    drawTable[2].origY = draw.y

    

        

        

    

    midPointX = math.abs(drawTable[1].origX+drawTable[2].origX)/2

    midPointY = math.abs(drawTable[1].origY+drawTable[2].origY)/2

    length = 

        math.sqrt(

        math.abs(drawTable[1].origX-drawTable[2].origX)^2 + 

        math.abs(drawTable[1].origY-drawTable[2].origY)^2

                )

                

        deltaX = drawTable[1].origX-drawTable[2].origX – used for calculating angle

        deltaY = drawTable[1].origY-drawTable[2].origY  – used for calculating angle

    angle = math.atan2(deltaY,deltaX)*(180/math.pi) – radian angle converted to degrees using 180/pi

    

    line = display.newRect(999,999,length,15)

    line.x = midPointX

    line.y = midPointY

    line.rotation = angle

    line:setFillColor(100,255,100)

    

    table.remove(drawTable,1)

    table.remove(drawTable,1) --removes both items in table

    

    print("=================================")

        for i =1,#drawTable do

        print(“Drawtable#”…i…"  x="…drawTable[i].origX…"  y="…drawTable[i].origY)

        end

    

    end

end

screen = display.newRect(0,0,width,height)

screen.alpha = 0

screen.isHitTestable = true

screen:addEventListener(“touch”,startDraw)

[/lua]


Hi @DCbball4life,

This is occurring because, at this time, anti-aliasing isn’t supported. In most cases, this is not too noticeable when you have a HD/Retina device and you set a content area that is near or matching the native resolution. However, I understand that some people want this feature; I believe it will be available in the upcoming graphics engine revamp, which is currently in beta testing.

Sincerely,

Brent Sorrentino