Skip to content

Commit

Permalink
Added show_collision property.
Browse files Browse the repository at this point in the history
If true, collision shapes are shown in the editor and at run-time.
Requires Visible Collision Shapes to be enabled in the Debug menu,
for collision shapes to be visible at run-time.
  • Loading branch information
Janglee123 committed Mar 4, 2021
1 parent c003423 commit 7b6cc3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/classes/TileMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@
<member name="occluder_light_mask" type="int" setter="set_occluder_light_mask" getter="get_occluder_light_mask" default="1">
The light mask assigned to all light occluders in the TileMap. The TileSet's light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
</member>
<member name="show_collision" type="bool" setter="set_show_collision" getter="is_show_collision_enabled" default="true">
If [code]true[/code], collision shapes are shown in the editor and at run-time. Requires [b]Visible Collision Shapes[/b] to be enabled in the [b]Debug[/b] menu for collision shapes to be visible at run-time.
</member>
<member name="tile_set" type="TileSet" setter="set_tileset" getter="get_tileset">
The assigned [TileSet].
</member>
Expand Down
16 changes: 15 additions & 1 deletion scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ void TileMap::update_dirty_quadrants() {
Color debug_collision_color;
Color debug_navigation_color;

bool debug_shapes = st && st->is_debugging_collisions_hint();
bool debug_shapes = show_collision && (Engine::get_singleton()->is_editor_hint() || (st && st->is_debugging_collisions_hint()));

if (debug_shapes) {
debug_collision_color = st->get_debug_collisions_color();
}
Expand Down Expand Up @@ -1792,6 +1793,15 @@ String TileMap::get_configuration_warning() const {
return warning;
}

void TileMap::set_show_collision(bool p_value) {
show_collision = p_value;
_recreate_quadrants();
}

bool TileMap::is_show_collision_enabled() const {
return show_collision;
}

void TileMap::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
Expand Down Expand Up @@ -1827,6 +1837,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);

ClassDB::bind_method(D_METHOD("set_show_collision", "enable"), &TileMap::set_show_collision);
ClassDB::bind_method(D_METHOD("is_show_collision_enabled"), &TileMap::is_show_collision_enabled);

ClassDB::bind_method(D_METHOD("set_centered_textures", "enable"), &TileMap::set_centered_textures);
ClassDB::bind_method(D_METHOD("is_centered_textures_enabled"), &TileMap::is_centered_textures_enabled);

Expand Down Expand Up @@ -1898,6 +1911,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "set_half_offset", "get_half_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_collision"), "set_show_collision", "is_show_collision_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");
Expand Down
4 changes: 4 additions & 0 deletions scene/2d/tile_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TileMap : public Node2D {
CollisionObject2D *collision_parent;
bool use_kinematic;
Navigation2D *navigation;
bool show_collision = true;

union PosKey {

Expand Down Expand Up @@ -277,6 +278,9 @@ class TileMap : public Node2D {

void update_dirty_quadrants();

void set_show_collision(bool p_value);
bool is_show_collision_enabled() const;

void set_collision_layer(uint32_t p_layer);
uint32_t get_collision_layer() const;

Expand Down

0 comments on commit 7b6cc3e

Please sign in to comment.