Merge pull request #575 from marynate/PR-node2d-set-global-pos
Add node2d::set_global_pos()
This commit is contained in:
commit
87af69b14d
2 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue