diff --git a/doc/classes/Node2D.xml b/doc/classes/Node2D.xml
index f38cfc101..6e6da7852 100644
--- a/doc/classes/Node2D.xml
+++ b/doc/classes/Node2D.xml
@@ -132,6 +132,9 @@
Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between [constant RenderingServer.CANVAS_ITEM_Z_MIN] and [constant RenderingServer.CANVAS_ITEM_Z_MAX] (inclusive).
+
+ If [code]true[/code], child nodes are sorted, otherwise sorting is disabled.
+
diff --git a/doc/classes/YSort.xml b/doc/classes/YSort.xml
index 7f5e541a0..e77b7466b 100644
--- a/doc/classes/YSort.xml
+++ b/doc/classes/YSort.xml
@@ -12,9 +12,6 @@
-
- If [code]true[/code], child nodes are sorted, otherwise sorting is disabled.
-
diff --git a/scene/2d/y_sort.cpp b/scene/2d/y_sort.cpp
index 9e5a9ba85..2e6a54dd7 100644
--- a/scene/2d/y_sort.cpp
+++ b/scene/2d/y_sort.cpp
@@ -31,24 +31,7 @@
#include "y_sort.h"
-void YSort::set_sort_enabled(bool p_enabled) {
- sort_enabled = p_enabled;
- RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled);
-}
-
-bool YSort::is_sort_enabled() const {
- return sort_enabled;
-}
-
-void YSort::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_sort_enabled", "enabled"), &YSort::set_sort_enabled);
- ClassDB::bind_method(D_METHOD("is_sort_enabled"), &YSort::is_sort_enabled);
-
- ADD_GROUP("Sort", "sort_");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sort_enabled"), "set_sort_enabled", "is_sort_enabled");
-}
-
YSort::YSort() {
- sort_enabled = true;
+ _sort_enabled = true;
RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true);
}
diff --git a/scene/2d/y_sort.h b/scene/2d/y_sort.h
index b95bba520..ff6040e28 100644
--- a/scene/2d/y_sort.h
+++ b/scene/2d/y_sort.h
@@ -36,12 +36,8 @@
class YSort : public Node2D {
GDCLASS(YSort, Node2D);
- bool sort_enabled;
- static void _bind_methods();
public:
- void set_sort_enabled(bool p_enabled);
- bool is_sort_enabled() const;
YSort();
};
diff --git a/scene/main/node_2d.cpp b/scene/main/node_2d.cpp
index 4a12d6eec..ce87a95ed 100644
--- a/scene/main/node_2d.cpp
+++ b/scene/main/node_2d.cpp
@@ -350,6 +350,19 @@ int Node2D::get_z_index() const {
return z_index;
}
+void Node2D::set_sort_enabled(bool p_enabled) {
+ if (_sort_enabled == p_enabled) {
+ return;
+ }
+
+ _sort_enabled = p_enabled;
+ RS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), _sort_enabled);
+}
+
+bool Node2D::is_sort_enabled() const {
+ return _sort_enabled;
+}
+
Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const {
if (p_parent == this) {
return Transform2D();
@@ -438,6 +451,9 @@ void Node2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &Node2D::set_z_as_relative);
ClassDB::bind_method(D_METHOD("is_z_relative"), &Node2D::is_z_relative);
+ ClassDB::bind_method(D_METHOD("set_sort_enabled", "enabled"), &Node2D::set_sort_enabled);
+ ClassDB::bind_method(D_METHOD("is_sort_enabled"), &Node2D::is_sort_enabled);
+
ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent", "parent"), &Node2D::get_relative_transform_to_parent);
ADD_GROUP("Transform", "");
@@ -456,6 +472,10 @@ void Node2D::_bind_methods() {
ADD_GROUP("Z Index", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_index", "get_z_index");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative");
+
+ ADD_GROUP("Sort", "sort_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sort_enabled"), "set_sort_enabled", "is_sort_enabled");
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toplevel"), "set_as_toplevel", "is_set_as_toplevel");
}
@@ -470,6 +490,7 @@ StringName Node2D::get_property_store_alias(const StringName &p_property) const
#endif
Node2D::Node2D() {
+ _sort_enabled = false;
angle = 0;
_scale = Vector2(1, 1);
_xform_dirty = false;
diff --git a/scene/main/node_2d.h b/scene/main/node_2d.h
index 88691471f..106b87254 100644
--- a/scene/main/node_2d.h
+++ b/scene/main/node_2d.h
@@ -52,6 +52,8 @@ class Node2D : public CanvasItem {
void _update_xform_values();
protected:
+ bool _sort_enabled;
+
void _notification(int p_notification);
static void _bind_methods();
@@ -114,6 +116,9 @@ public:
void set_z_as_relative(bool p_enabled);
bool is_z_relative() const;
+ void set_sort_enabled(bool p_enabled);
+ bool is_sort_enabled() const;
+
Transform2D get_relative_transform_to_parent(const Node *p_parent) const;
Transform2D get_transform() const;