Skip to content

Commit

Permalink
Merge pull request godotengine#15 from JiepengTan/spx4.2.2
Browse files Browse the repository at this point in the history
Collider add spx debug mode(draw debug shape)
  • Loading branch information
JiepengTan authored Nov 18, 2024
2 parents 931c937 + 3335575 commit 5e26832
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
11 changes: 4 additions & 7 deletions core/extension/spx_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ void SpxSprite::_draw() {
if (!Spx::debug_mode) {
return;
}
if (trigger2d != nullptr && trigger2d->get_shape() != nullptr) {
Ref<Shape2D> trigger_shape = trigger2d->get_shape();
trigger_shape->draw(get_canvas_item(), Color(1, 0, 0, 0.2));
if(trigger2d != nullptr) {
trigger2d->set_spx_debug_color(Color(1, 0, 0, 0.2));
}

if (collider2d != nullptr && collider2d->get_shape() != nullptr) {
Ref<Shape2D> collider_shape = collider2d->get_shape();
collider_shape->draw(get_canvas_item(), Color(0, 0, 1, 0.2));
if(collider2d != nullptr) {
collider2d->set_spx_debug_color(Color(0, 0, 1, 0.2));
}
}

Expand Down
7 changes: 6 additions & 1 deletion scene/2d/collision_shape_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "collision_shape_2d.h"

#include "collision_object_2d.h"
#include "core/extension/spx.h"
#include "scene/2d/area_2d.h"
#include "scene/resources/concave_polygon_shape_2d.h"
#include "scene/resources/convex_polygon_shape_2d.h"
Expand Down Expand Up @@ -90,7 +91,11 @@ void CollisionShape2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());

if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint() && !Spx::debug_mode) {
break;
}

if(Spx::debug_mode && !is_enable_spx_debug) {
break;
}

Expand Down
5 changes: 5 additions & 0 deletions scene/2d/collision_shape_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CollisionShape2D : public Node2D {
bool one_way_collision = false;
real_t one_way_collision_margin = 1.0;
Color debug_color;
bool is_enable_spx_debug;

void _shape_changed();
void _update_in_shape_owner(bool p_xform_only = false);
Expand Down Expand Up @@ -82,6 +83,10 @@ class CollisionShape2D : public Node2D {

PackedStringArray get_configuration_warnings() const override;

void set_spx_debug_color(const Color &p_color) {
is_enable_spx_debug = true;
debug_color = p_color;
}
CollisionShape2D();
};

Expand Down
1 change: 1 addition & 0 deletions testaaaf
Submodule testaaaf added at 7edb84

0 comments on commit 5e26832

Please sign in to comment.