Stretch/skew a 2D sprite by moving the top 2 vertices?

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

I want a simple effect for my 2D game, where the character lands in something sticky, and the jump height is drastically reduced.

All I want is to take the following sprite;

and fix the bottom 2 vertexes to the ground, and the top 2 vertexes to the bottom of the player sprite. So that as they jump, the image stretches to follow them, appearing to pull them back down due to their reduced jump height.

How can I control the vertexes of a sprite in this way? BTW I’m still using Godot 2.1.

:bust_in_silhouette: Reply From: Zylann

Sprites are just an easy-to-use textured rectangle, so there is no function to skew it freely, except maybe using shaders.

If you want to do this, I would suggest using a custom-drawn polygon, by creating a Node2D, overriding the _draw() method and using draw_primitive(). This lets you define exactly where each vertex will be, as well as texture coordinates and colors.

You could also use the Polygon2D node.

Thank you, I will look into those options :slight_smile:

Domarius | 2019-01-26 12:10