Draw a Line on the screen

Hi! So I’m making a game, and I want to make a system that continually draws a line wherever a player has been. I could create a thin rectangle to act as a line, but that seems inefficient and wouldn’t create a smooth (possibly curved) path.

Is there any efficient way of how to do this?

Thanks in advanced!

Sure, just make a line and add vertices to it:

I would ONLY add new vertices once the player has traveled a certain distance or more from the last one however or you will quickly have a huge number of vertices in your line.

Note: If you want to make the path smooth, you’ll have to progressively smooth the last N vertices, using a spline (or other similar) calculation.  The key is to do this on-demand to avoid high costs.

Awesome! This is exactly what I was looking for. One more question: Is there a way I can make 1 end of the line some color, and the line becomes progressivly more transparent until its invisible at the other end?

No.

Single lines are rendered in a single color.  

The only way to get that effect is to make the line in discrete segments or from rectangles.

By the way.  No need to quote when responding.  Just respond.  Quoting should only be used for short bits you want to specifically focus on.  Quoting all the time just makes posts hard to read.

Cheers,

Ed

Tip - If you have several respondents to a post and want to reply to a particular responder, just use this response style:

@personsname,

Thanks for the input… blah blah blah…

@roaminggamer,

I’ll keep that in mind. Thanks for the help.

@roaminggamer,

Hey, so I want to have multiple lines that vary in transparency and move relative to the player(The player stays centered in the middle of the screen). However, whenever I add a line to a group, the line disappears. Any idea of how to fix this/why this is happening?

They say a picture speaks a thousand words and in cases like this it really does!  Objects added to a display group will stay there until manually removed.

Are you moving the x and y position of the group at all? Objects placed into a group are positioned relative to the group itself.  

If you have a group at 1000, 1000 and insert a rect at 50, 50. The rect would appear at 1050, 1050 relative to the screen.

Sure, just make a line and add vertices to it:

I would ONLY add new vertices once the player has traveled a certain distance or more from the last one however or you will quickly have a huge number of vertices in your line.

Note: If you want to make the path smooth, you’ll have to progressively smooth the last N vertices, using a spline (or other similar) calculation.  The key is to do this on-demand to avoid high costs.

Awesome! This is exactly what I was looking for. One more question: Is there a way I can make 1 end of the line some color, and the line becomes progressivly more transparent until its invisible at the other end?

No.

Single lines are rendered in a single color.  

The only way to get that effect is to make the line in discrete segments or from rectangles.

By the way.  No need to quote when responding.  Just respond.  Quoting should only be used for short bits you want to specifically focus on.  Quoting all the time just makes posts hard to read.

Cheers,

Ed

Tip - If you have several respondents to a post and want to reply to a particular responder, just use this response style:

@personsname,

Thanks for the input… blah blah blah…

@roaminggamer,

I’ll keep that in mind. Thanks for the help.

@roaminggamer,

Hey, so I want to have multiple lines that vary in transparency and move relative to the player(The player stays centered in the middle of the screen). However, whenever I add a line to a group, the line disappears. Any idea of how to fix this/why this is happening?

They say a picture speaks a thousand words and in cases like this it really does!  Objects added to a display group will stay there until manually removed.

Are you moving the x and y position of the group at all? Objects placed into a group are positioned relative to the group itself.  

If you have a group at 1000, 1000 and insert a rect at 50, 50. The rect would appear at 1050, 1050 relative to the screen.