Godot Version
4.2.2.stable.official
Question
I have a class called DamageZone deriving from Area2D that is added to my scene programmatically. I’m adding 2 child nodes to it in the _init function: a CollisionPolygon2D to be able to check for overlapping bodies, and a Polygon2D to be able to show the area in the game.
I can see the Polygon2D appearing in the scene when I play, but even though I’m setting the color to a semi-transparent orange, it is always opaque and white. Can anyone help me figure out what I’m doing wrong?
Here’s the code of my class:
extends Area2D
class_name DamageZone
const DEFAULT_COLOR: Color = Color(186, 90, 29, 142)
var collision_polygon: CollisionPolygon2D
var polygon: Polygon2D
func _init(p_vertices: PackedVector2Array):
collision_polygon = CollisionPolygon2D.new()
collision_polygon.set_polygon(p_vertices)
add_child(collision_polygon)
polygon = Polygon2D.new()
polygon.set_polygon(p_vertices)
polygon.z_index = 2
polygon.set_color(DEFAULT_COLOR)
add_child(polygon)