Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used this command to create a line:

local myLine = display.newLine( 0,-110, 27,-35 )

How can I get the coordinates from myLine? I've looked here and here but the closest thing I could find is myLine.x and myLine.y, which appear to be x1 and y1 (not sure), but I can't figure out how to get x2 and y2.

I want this information in order to detect if two lines intersect on the screen.

share|improve this question
You just created the line and passed the coordinates in. How can you not have them afterward? – Byte56 Apr 18 '12 at 20:50
up vote 1 down vote accepted

I have never used Corona before but reading through the documentation I believe you can't easily retrieve these coordinates back from the generated display object. From what I read, display.newLine returns a vector display object to which you can append as many vertices as you want, but there's no way to access those values.

I guess you could use line.contentBounds to get back the size of the rectangle that encompasses the line, but this wouldn't tell you which diagonal to pick.

What I would suggest is to encapsulate this behavior in your own separate Line class (if that's possible in Corona) which stores the vertices, provides access to them, and generates the display object for you. Since I'm not familiar with Corona I'll use another language, but try to think of it as pseudocode.

I hope you can understand the general idea and can adapt it to some Corona equivalent. Let me know if there's something you don't understand:

class Line
     public Line(int x1, int y1, int x2, int y2)
         this.x1 = x1;
         this.y1 = y1;
         this.x2 = x2;
         this.y2 = y2;

     public int x1, y1, x2, y2;

     public DisplayObject GetDisplayObject()
         return display.newLine(x1, y1, x2, y2);

     public bool Intersects(Line other) 
         // Line segment intersection algorithm
share|improve this answer

A simpler solution could be to add yourself the properties to your line

local line = display.newLine( x1,y1, x2,y2 )
line.x1 = x1
line.x2 = x2
line.y1 = y1
line.y2 = y2

then later you can grab line.x2, line.y2

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.