diff options
author | marynate <mary.w.nate@gmail.com> | 2014-07-01 22:07:04 +0800 |
---|---|---|
committer | marynate <mary.w.nate@gmail.com> | 2014-07-07 19:08:26 +0800 |
commit | a62305e0e3296dc226f469a75b25f72163873e85 (patch) | |
tree | 559af5ac30943ddb2decc507b11b57f481564221 | |
parent | 3d68949a1cc41b4865618bddde23122f66764ee1 (diff) |
Add node2d::get_global_pos()
-rw-r--r-- | scene/2d/node_2d.cpp | 13 | ||||
-rw-r--r-- | scene/2d/node_2d.h | 1 |
2 files changed, 14 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); diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 8e1f22c235..582c56fa9b 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -83,6 +83,7 @@ public: void set_transform(const Matrix32& p_transform); void set_global_transform(const Matrix32& p_transform); + void set_global_pos(const Point2& p_pos); Matrix32 get_transform() const; |