summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-01-12 13:48:17 +0100
committerGitHub <noreply@github.com>2018-01-12 13:48:17 +0100
commitbab9759645d29686c480d9bd0e6b1c50e4f541ef (patch)
tree2284d1d6fe5dfc7a763d0323fb99ae8c8565c28a /scene/2d
parent3a05d974e0fb925869fe0fdfdbde9da8ee6a2757 (diff)
parentaefedb73fcba789207db4da0d27214eecaf0f078 (diff)
Merge pull request #15606 from RandomShaper/fix-inherited-coll-shapes
Update collision shapes data on tree entered
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/collision_polygon_2d.cpp22
-rw-r--r--scene/2d/collision_polygon_2d.h2
-rw-r--r--scene/2d/collision_shape_2d.cpp22
-rw-r--r--scene/2d/collision_shape_2d.h2
4 files changed, 40 insertions, 8 deletions
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index 965507e385..978fb379ac 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -115,6 +115,15 @@ Vector<Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() {
return decomp;
}
+void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) {
+
+ parent->shape_owner_set_transform(owner_id, get_transform());
+ if (p_xform_only)
+ return;
+ parent->shape_owner_set_disabled(owner_id, disabled);
+ parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+}
+
void CollisionPolygon2D::_notification(int p_what) {
switch (p_what) {
@@ -124,9 +133,7 @@ void CollisionPolygon2D::_notification(int p_what) {
if (parent) {
owner_id = parent->create_shape_owner(this);
_build_polygon();
- parent->shape_owner_set_transform(owner_id, get_transform());
- parent->shape_owner_set_disabled(owner_id, disabled);
- parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+ _update_in_shape_owner();
}
/*if (Engine::get_singleton()->is_editor_hint()) {
@@ -136,10 +143,17 @@ void CollisionPolygon2D::_notification(int p_what) {
}*/
} break;
+ case NOTIFICATION_ENTER_TREE: {
+
+ if (parent) {
+ _update_in_shape_owner();
+ }
+
+ } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
- parent->shape_owner_set_transform(owner_id, get_transform());
+ _update_in_shape_owner(true);
}
} break;
diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h
index 83451f3f1a..4dafe7d1da 100644
--- a/scene/2d/collision_polygon_2d.h
+++ b/scene/2d/collision_polygon_2d.h
@@ -59,6 +59,8 @@ protected:
void _build_polygon();
+ void _update_in_shape_owner(bool p_xform_only = false);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index bf213614ed..0eeb6dafe5 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -45,6 +45,15 @@ void CollisionShape2D::_shape_changed() {
update();
}
+void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) {
+
+ parent->shape_owner_set_transform(owner_id, get_transform());
+ if (p_xform_only)
+ return;
+ parent->shape_owner_set_disabled(owner_id, disabled);
+ parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+}
+
void CollisionShape2D::_notification(int p_what) {
switch (p_what) {
@@ -57,9 +66,7 @@ void CollisionShape2D::_notification(int p_what) {
if (shape.is_valid()) {
parent->shape_owner_add_shape(owner_id, shape);
}
- parent->shape_owner_set_transform(owner_id, get_transform());
- parent->shape_owner_set_disabled(owner_id, disabled);
- parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+ _update_in_shape_owner();
}
/*if (Engine::get_singleton()->is_editor_hint()) {
@@ -69,10 +76,17 @@ void CollisionShape2D::_notification(int p_what) {
}*/
} break;
+ case NOTIFICATION_ENTER_TREE: {
+
+ if (parent) {
+ _update_in_shape_owner();
+ }
+
+ } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
- parent->shape_owner_set_transform(owner_id, get_transform());
+ _update_in_shape_owner(true);
}
} break;
diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h
index b3f7d3f02a..cdff595828 100644
--- a/scene/2d/collision_shape_2d.h
+++ b/scene/2d/collision_shape_2d.h
@@ -47,6 +47,8 @@ class CollisionShape2D : public Node2D {
bool disabled;
bool one_way_collision;
+ void _update_in_shape_owner(bool p_xform_only = false);
+
protected:
void _notification(int p_what);
static void _bind_methods();