Draw a line trailing behind a moving object

I'm working with monogame, moving a sprite object up and down. I want to draw a trail from the sprite's position and scrolling off to the left of the screen - like the sprite was a pencil leaving marks on a long sheet of paper sliding underneath it.

Here is an animated example:

I know how to move the sprite up and down but I'm a bit lost on how to do the trailing part. If someone could point me in the right direction I would really appreciate it

• Could you reupload the image to stack's imgur account using the 'image' tool in the edit bar? This would prevent link rot in case pastebord.co shuts down or decide to remove the image. – Vaillancourt Jan 25 '17 at 12:44

A point, in the right direction?

You should have an array for points that will be drawn on the screen. And every frame, you should be capturing the position of the player and adding that to that array. Then, iterate through the array to add points to the screen. To reduce lag, you can also delete points from the array that have left the screen.

e.g.:

// The following code will not run properly:

public Vector2 playerPosition;

// Assume some code is here

public Vector2[] pointPositions;

public void Update()
{
for(int i = 0; i < pointPositions.length; i++)
{
// Assuming your positions are in pixels
pointPositions[i].X = pointPositions[i].X - 1;
}
pointPositions += playerPosition;
}

public void Draw()
{
for(int i = 0; i < pointPositions.length; i++)
{
// Assuming you have a drawPoint(Vector2) function:
drawPoint(pointPositions[i]);
}
}

• The heart is moving up and down only, not left to right, so at each frame, each of the points should be moved one pixel left. – Vaillancourt Jan 25 '17 at 17:21
• Yeah, that too. I didn't think about that. – user96776 Jan 25 '17 at 19:02
• Thanks for the answer. In fact I actually did that before you posted. Works like a charm. I will accept this as the answer – Eminem Jan 26 '17 at 5:32