- Edited
To be honest, no idea what I am doing wrong here: I am using below code to draw a hexagon shape with a Polygon2D and assign a texture to it:
extends Polygon2D
var edgeLength = 100
# Called when the node enters the scene tree for the first time.
func _ready():
drawTile()
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func drawTile():
var height = sqrt(3) * edgeLength
print(height)
var pt0 = Vector2(edgeLength,0)
var pt1 = Vector2(pt0.x + edgeLength, 0)
var pt2 = Vector2(pt1.x + 0.5*edgeLength, pt1.y + height*0.5)
var pt3 = Vector2(pt1.x, pt1.y + height)
var pt4 = Vector2(pt0.x, pt1.y + height)
var pt5 = Vector2(pt0.x - 0.5*edgeLength, pt1.y + height*0.5)
var texture = load("res://tex/hex_grasland_430_371.png")
var array = PackedVector2Array([pt0, pt1, pt2, pt3, pt4, pt5, pt0])
print(array)
self.polygon = array
self.texture = texture
self.set_texture_scale(Vector2(1,1))
add_child(self)
The texture looks like below:
When setting the edgeLength to 100 the output is
Setting it to 75 and it looks like
What do I need to change to make sure that the texture always properly fills the hexagon and that the hexagon itself is drawn properly?