Drawing a texture stretched between four given points

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SamButers

I have been wondering if Godot has any function to transform or draw a texture with the manipulation of its four points: x0, x1, y0 and y1.

Example of the desired effect is represented below with each point being the red dots:
Kelpie is doing fine

Kelpie has been stretched beyond recognition but is still doing fine

:bust_in_silhouette: Reply From: njamster

Create a Polygon2D-node. Select it in the scene tree and add four points to it via the toolbar on top of the 2D scene view by first clicking the green plus icon and then into the scene, where you want your polygon’s corner-points to be. Next, in the inspector, set your image as the texture of the polygon. Navigate back to the toolbar and click on the “UV”-icon. A popup will open and allow you to move the UV-points to the corners of your texture. Note that changing the UV-points will not change the corner-points of the polygon we set earlier! If you press “OK” everything between the UV-points will now be mapped (by shearing and stretching) into the area inside your polygon.

This seems like a good way to solve this, yes.
Using the points section seems to bring the desired effect, although
I have been wondering how to access that through GDScript.
I have seen some functions dedicated to manipulation the bones, UV,
polygons but not the points in there.

But, yes, appreciated.
Seems like what I was looking for.

SamButers | 2020-04-17 19:11

Was testing out stuff and the points can be modified
through the polygon property, although I was a little
confused in the beginning with the polygon and polygons properties,
one of them having no description.

That being said, all have been solved.

SamButers | 2020-04-17 19:45


Can you explain how to access the points property ?
I want to animate the sprite with a tween.


[EDIT → self solution]

If found a solution :

$Polygon2d.polygon[index of the desired point]
Return Vector 2D coordinates.

PEIGNAULT Laurent | 2021-01-17 16:59