0 votes

I have a scene with two sprites like this
enter image description here

so in my script, I create two 2D polygons using this:

var sprite1 = $Sprite1 # My mask (may be rotated and/or scaled)
var sprite2 = $Sprite2
# create a polygon from sprite 1
var b = BitMap.new()
b.create_from_image_alpha(sprite1.texture.get_data(), 0)
var polygons = b.opaque_to_polygons(Rect2(Vector2.ZERO, sprite1.texture.get_size()), 0)
# Create two 2D polygons using the polygon obtained by the previous method.
var polygon2d_back = Polygon2D.new()
polygon2d_back.polygon = polygon
polygon2d_back.position = sprite1.position
var polygon2d_top = Polygon2D.new()
polygon2d_top.polygon = polygon
polygon2d_top.position = sprite1.position

and now I need to know how to get the correct UV to put the textures of sprite1 and sprite2 in both polygons to get this result:

enter image description here

# Set textures and UVs (note that sprite1 (the mask) may be rotated or scaled.)
polygon2d_back.texture = sprite2.texture
polygon2d_back.uv = # ????????????????? <------------ How do I calculate this?

polygon2d_top.texture = sprite1.texture
polygon2d_top.uv = # ????????????????? <------------ How do I calculate this?
Godot version 3.2.3
in Engine by (184 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.