summaryrefslogtreecommitdiff
path: root/scene/2d/collision_shape_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/collision_shape_2d.cpp')
-rw-r--r--scene/2d/collision_shape_2d.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index b1dbc57c94..88d124536c 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -41,26 +41,22 @@
#include "scene/resources/segment_shape_2d.h"
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)
+ 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);
parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin);
}
void CollisionShape2D::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_PARENTED: {
-
parent = Object::cast_to<CollisionObject2D>(get_parent());
if (parent) {
owner_id = parent->create_shape_owner(this);
@@ -78,14 +74,12 @@ 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) {
_update_in_shape_owner(true);
}
@@ -100,7 +94,6 @@ void CollisionShape2D::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
-
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
break;
}
@@ -137,8 +130,9 @@ void CollisionShape2D::_notification(int p_what) {
pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
cols.push_back(draw_col);
+ }
draw_primitive(pts, cols, Vector<Vector2>());
}
@@ -147,9 +141,9 @@ void CollisionShape2D::_notification(int p_what) {
}
void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
-
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->disconnect("changed", callable_mp(this, &CollisionShape2D::_shape_changed));
+ }
shape = p_shape;
update();
if (parent) {
@@ -159,27 +153,26 @@ void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
}
}
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->connect("changed", callable_mp(this, &CollisionShape2D::_shape_changed));
+ }
update_configuration_warning();
}
Ref<Shape2D> CollisionShape2D::get_shape() const {
-
return shape;
}
bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
-
- if (!shape.is_valid())
+ if (!shape.is_valid()) {
return false;
+ }
return shape->_edit_is_selected_on_click(p_point, p_tolerance);
}
String CollisionShape2D::get_configuration_warning() const {
-
if (!Object::cast_to<CollisionObject2D>(get_parent())) {
return TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape.");
}
@@ -212,7 +205,6 @@ void CollisionShape2D::set_one_way_collision(bool p_enable) {
}
bool CollisionShape2D::is_one_way_collision_enabled() const {
-
return one_way_collision;
}
@@ -228,7 +220,6 @@ float CollisionShape2D::get_one_way_collision_margin() const {
}
void CollisionShape2D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape2D::set_shape);
ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape2D::get_shape);
ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionShape2D::set_disabled);
@@ -245,7 +236,6 @@ void CollisionShape2D::_bind_methods() {
}
CollisionShape2D::CollisionShape2D() {
-
rect = Rect2(-Point2(10, 10), Point2(20, 20));
set_notify_local_transform(true);
owner_id = 0;