Finally we can add a trail to the ball.
Add a Line2D Node as a child of the Sprite2D
Rename the Line2D to trail_line
Add a New Script to the trail_line Node
A line is simply a collection of overlapping points
We can draw a line by adding a point at the current position.
The line will not draw correctly until we turn on Top Level
This overrides the draw order of the scene tree and allows
the line to follow the ball.
To shorten the trail we set a limit to the number
of points we draw - 30. If more than 30 points
have been drawn, we remove the first one.
Currently the line is drawn from the centre of the ball
We want to draw it from the edge (perimeter)
So we need to calculate the radius of the ball.
This will be half the size (width) of the ball image.
We also need to know where on the perimeter we should draw the tail.
We need to know what direction the ball is heading in so that the trail is drawn in the correct place.
Add variables to store the previous position of the ball
and the radius of the ball.
get the texture of the ball
set the previous position
calculate the direction the ball is moving
update the previous position
Select the trail_line node
Click on Width Curve and Select New Curve
Click on the Curve to open the properties
Draw a curve manually or click on Presets
Choose a Default colour for the line
Adjust the Alpha channel to make it opaque
In the Fill Section add a New Colour Gradient
Choose two colours to transition between
Set the Joint Mode to Round
Set the Beginning Cap to Round
This gives our trail a Tapered appearance
This concludes the tutorial