diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-03-13 13:57:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-13 13:57:58 +0100 |
commit | c81356153e2381c2c3c909b0ca2774899bba7a80 (patch) | |
tree | 9704c63a5dc5b3ba0bf05e1884bc1ada58514366 /scene/2d | |
parent | 65dc4abca38a697505d4762c8af1b61fc2726fe2 (diff) | |
parent | 7effe46461090861cae417f30db29e4c14a83db2 (diff) |
Merge pull request #16971 from Noshyaar/tilemap
TileMap: add fix_invalid_tiles
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/tile_map.cpp | 11 | ||||
-rw-r--r-- | scene/2d/tile_map.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 3af77bfcc7..b602839b99 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -834,6 +834,16 @@ void TileMap::update_dirty_bitmask() { } } +void TileMap::fix_invalid_tiles() { + + for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { + + if (!tile_set->has_tile(get_cell(E->key().x, E->key().y))) { + set_cell(E->key().x, E->key().y, INVALID_CELL); + } + } +} + int TileMap::get_cell(int p_x, int p_y) const { PosKey pk(p_x, p_y); @@ -1519,6 +1529,7 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("is_cell_y_flipped", "x", "y"), &TileMap::is_cell_y_flipped); ClassDB::bind_method(D_METHOD("is_cell_transposed", "x", "y"), &TileMap::is_cell_transposed); + ClassDB::bind_method(D_METHOD("fix_invalid_tiles"), &TileMap::fix_invalid_tiles); ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear); ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells); diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 104842d52f..587bd3b684 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -310,6 +310,7 @@ public: void set_clip_uv(bool p_enable); bool get_clip_uv() const; + void fix_invalid_tiles(); void clear(); TileMap(); |