Set up transform notification for VertexLight2D.

This commit is contained in:
Relintai 2024-03-24 21:55:18 +01:00
parent 9ce6ebc1b5
commit 9df448113d
2 changed files with 17 additions and 5 deletions

View File

@ -36,7 +36,7 @@ Color VertexLight2D::get_color() {
} }
void VertexLight2D::set_color(const Color &p_color) { void VertexLight2D::set_color(const Color &p_color) {
_color = p_color; _color = p_color;
VertexLights2DServer::get_singleton()->light_set_color(_vertex_light, _color); VertexLights2DServer::get_singleton()->light_set_color(_vertex_light, _color);
} }
@ -45,7 +45,7 @@ VertexLight2D::VertexLight2DMode VertexLight2D::get_mode() {
} }
void VertexLight2D::set_mode(const VertexLight2D::VertexLight2DMode p_mode) { void VertexLight2D::set_mode(const VertexLight2D::VertexLight2DMode p_mode) {
_mode = p_mode; _mode = p_mode;
VertexLights2DServer::get_singleton()->light_set_mode(_vertex_light, (VertexLights2DServer::VertexLight2DMode)_mode); VertexLights2DServer::get_singleton()->light_set_mode(_vertex_light, (VertexLights2DServer::VertexLight2DMode)_mode);
} }
@ -54,7 +54,7 @@ Vector2i VertexLight2D::get_z_range() {
} }
void VertexLight2D::set_z_range(const Vector2i &p_z_range) { void VertexLight2D::set_z_range(const Vector2i &p_z_range) {
_z_range = p_z_range; _z_range = p_z_range;
VertexLights2DServer::get_singleton()->light_set_z_range(_vertex_light, _z_range); VertexLights2DServer::get_singleton()->light_set_z_range(_vertex_light, _z_range);
} }
@ -63,7 +63,7 @@ Vector2i VertexLight2D::get_layer_range() {
} }
void VertexLight2D::set_layer_range(const Vector2i &p_layer_range) { void VertexLight2D::set_layer_range(const Vector2i &p_layer_range) {
_layer_range = p_layer_range; _layer_range = p_layer_range;
VertexLights2DServer::get_singleton()->light_set_layer_range(_vertex_light, _layer_range); VertexLights2DServer::get_singleton()->light_set_layer_range(_vertex_light, _layer_range);
} }
@ -72,7 +72,7 @@ int VertexLight2D::get_item_cull_mask() {
} }
void VertexLight2D::set_item_cull_mask(const int p_item_cull_mask) { void VertexLight2D::set_item_cull_mask(const int p_item_cull_mask) {
_item_cull_mask = p_item_cull_mask; _item_cull_mask = p_item_cull_mask;
VertexLights2DServer::get_singleton()->light_set_item_cull_mask(_vertex_light, _item_cull_mask); VertexLights2DServer::get_singleton()->light_set_item_cull_mask(_vertex_light, _item_cull_mask);
} }
@ -83,12 +83,22 @@ VertexLight2D::VertexLight2D() {
_item_cull_mask = 1; _item_cull_mask = 1;
_z_range = Vector2i(-1024, 1024); _z_range = Vector2i(-1024, 1024);
_mode = VERTEX_LIGHT_2D_MODE_ADD; _mode = VERTEX_LIGHT_2D_MODE_ADD;
set_notify_transform(true);
} }
VertexLight2D::~VertexLight2D() { VertexLight2D::~VertexLight2D() {
VertexLights2DServer::get_singleton()->free(_vertex_light); VertexLights2DServer::get_singleton()->free(_vertex_light);
} }
void VertexLight2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
VertexLights2DServer::get_singleton()->light_set_position(_vertex_light, get_global_transform().get_origin());
} break;
}
}
void VertexLight2D::_bind_methods() { void VertexLight2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_color"), &VertexLight2D::get_color); ClassDB::bind_method(D_METHOD("get_color"), &VertexLight2D::get_color);
ClassDB::bind_method(D_METHOD("set_color", "color"), &VertexLight2D::set_color); ClassDB::bind_method(D_METHOD("set_color", "color"), &VertexLight2D::set_color);

View File

@ -71,6 +71,8 @@ public:
~VertexLight2D(); ~VertexLight2D();
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
RID _vertex_light; RID _vertex_light;