display.newLine( )

Description:

Draw a line from one point to another. Optionally, append points to the end of the line. See Polylines.

Syntax:

display.newLine( [parent,] x1,y1, x2,y2 )

Example:

local star = display.newLine( 0,-110, 27,-35 )
star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110 )
star:setColor( 255, 102, 102, 255 )
star.width = 3 

Parameters:

parent
object: Specify an optional display group in which to insert the line. Uses the current Stage if not specified.

x1,y1
number: Coordinates of the beginning of the line.

x2,y2
number: Coordinates of the end of the line.

Returns:

Display object

Remarks:

Note: Currently display.newLine objects do not support touch events (case #3803).

By default, the fill color is white (rgb 255, 255, 255). The default color can be changed using display.setDefault.

Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 2.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 2.0
  • Android:
    Corona SDK 2.0

Replies

PValentini
User offline. Last seen 15 weeks 1 hour ago. Offline
Joined: 21 May 2010

Bug Report!
With this code we can check a bug, there is any solution to fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- LINES DEBUG
local function newLine(pts)
        local l = display.newLine(pts[1][1], pts[1][2], pts[2][1], pts[2][2])
        for i=3, #pts, 1 do
                l:append(pts[i][1], pts[i][2])
        end
        l:setColor(255,255,255,255*0.8)
        l.width = 2
end
 
-- BUG, NOT WORK!!! BECAUSE BACK THE POINT..
newLine({{100,100},{300,100},{10,100}}) 
 
-- WORK!!! BACK BUT 1 PIXEL DIFF
newLine({{100,100},{300,100},{10,101}}) 

I'm working in an alternative solution that detect when the line change direction and create other line in this point, there is any way to detect this? It can solve this bug...

Tom
User offline. Last seen 18 hours 21 min ago. Offline
Staff
Joined: 13 Jul 2010

Sorry, but we cannot process bug reports here. Please report the bug through the "Report a Bug" link on the Corona developer's page.

jpot328
User offline. Last seen 2 years 10 weeks ago. Offline
Joined: 31 Jan 2011

JUST A LITTLE TIP:

I noticed whenever one draws a shape using display.newLine() by starting the first line on a corner or point (such as the tip of the star in this example) that the lines do not join into a corner or point as they do on the other corners or points. For example, if you look closely at each point on the star from the example code above, you will notice that every point is joined together to make nice sharp points except for the top point, which is where the line segments begin and end. The easy fix for this is to not start a shape on a corner or point, but to start half way through a straight line portion. I start my first line on the horizontal segment on the middle-right point. As a result, when you look at the star from my code you will notice that all 5 points are sharp, and there are no un-joined segments.

1
2
3
local star = display.newLine( 50,-35,  105,-35 ) 
star:append( 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110, 27,-35, 50,-35 )
star:setColor( 0, 170, 0 )

mrgoose
User offline. Last seen 1 year 12 weeks ago. Offline
Joined: 24 Jun 2009

"By default, the fill color is white (rgb 255, 255, 255). The default color can be changed using display.setDefault."

Don't think this is accurate. By default, there is no fill, and can't seem to allpy setFillColor to a "shape/polyline" created with newLine???

makelvin
User offline. Last seen 1 year 19 weeks ago. Offline
Joined: 17 Jan 2011

@mrgoose, I agree. Since the polyline cannot be filled, the line about the default fill color should definitely be removed or be clarified further. It simply does not make any sense at all.

makelvin
User offline. Last seen 1 year 19 weeks ago. Offline
Joined: 17 Jan 2011

@mrgoose, I agree. Since the polyline cannot be filled, the line about the default fill color should definitely be removed or be clarified further. It simply does not make any sense at all.

neal97
User offline. Last seen 12 weeks 3 days ago. Offline
Joined: 2 Apr 2012

Is there a way to anti-alias these lines?

nglenister
User offline. Last seen 7 weeks 6 days ago. Offline
Joined: 24 Aug 2012

+1 for anti-aliasing

nglenister
User offline. Last seen 7 weeks 6 days ago. Offline
Joined: 24 Aug 2012

Add antialias = true to content in your config file