Draw a line or colors to showcase the touch and slide path on screen

Hi,
My use case is that the there are two sprites on the screen at some distance, when player touch one sprite and slide on screen without releasing to another sprite, I want to draw the path with some thickness and colour.
Input events, I have taken care of.
All I need is drawing the path.
Ways, I can think of:

  1. Use a small rectangle sprite and using factory keep adding on screen or removing as per path (very resource hungry)
  2. Use GUI node - box to draw and keep changing its position and size.
  3. Using render low level draw functions to draw rectangle and color it (which I don’t know how to achieve and will need some references)

is there any better method or which one from above is better to implement ?

Thanks

Is it a problem? Have you tried? Defold can draw thousands of sprites without a hitch.

One more option might be to do something using a shader, similar to this: Hyper Trails

1 Like

Nope, I didn’t try, gonna try both solutions and will share here
Thanks

You also have the mesh component, which allows you to alter the vertices+uvs at runtime.

1 Like

You could use a rectangle sprite and scale it to reach from A to B.

4 Likes

Hi,
may you please give some hint here
as on animating scale.x its look like as if rectangle is growing from center

Yes, it is so by design. If you want to scale the sprite by keeping its left end still then you should offset the position of the sprite with respect to the containing game object whose scale you are animation. Move the sprite position so that the left end is at the position of the game object.

I hope this helps.

2 Likes

thanks , animating both scale.x and position works