summaryrefslogtreecommitdiff
path: root/scene/2d/node_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/node_2d.cpp')
-rw-r--r--scene/2d/node_2d.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 9c28212529..4c00db2429 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -253,6 +253,18 @@ Point2 Node2D::get_global_pos() const {
return get_global_transform().get_origin();
}
+void Node2D::set_global_pos(const Point2& p_pos) {
+
+ Matrix32 inv;
+ CanvasItem *pi = get_parent_item();
+ if (pi) {
+ inv = pi->get_global_transform().affine_inverse();
+ set_pos(inv.xform(p_pos));
+ } else {
+ set_pos(p_pos);
+ }
+}
+
void Node2D::set_transform(const Matrix32& p_transform) {
_mat=p_transform;
@@ -297,6 +309,7 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos);
+ ObjectTypeDB::bind_method(_MD("set_global_pos"),&Node2D::set_global_pos);
ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform);
ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform);