Skip to content

Commit

Permalink
feat: TiledAtlas.clearCache function (#2592)
Browse files Browse the repository at this point in the history
Possibility to clear TiledAtlas cache. This is required after Flame.images.clearCache() call.
  • Loading branch information
ASGAlex committed Jun 29, 2023
1 parent 45115bb commit d40fefc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/bridge_packages/flame_tiled/flame_tiled.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ final component = await TiledComponent.load(
);
```


### Clearing images cache

If you have called `Flame.images.clearCache()` you also need to call `TiledAtlas.clearCache()` to
remove disposed images from the tiled cache. It might be useful if your next game map have completely
different tiles than the previous.

[Tiled]: https://www.mapeditor.org/

```{toctree}
Expand Down
8 changes: 8 additions & 0 deletions packages/flame_tiled/lib/src/tile_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ class TiledAtlas {
key: key,
);
}

/// Clears images cached in `TiledAtlas`
///
/// If you called `Flame.images.clearCache()` you also need to call this
/// function to clear disposed images from tiled cache.
static void clearCache() {
atlasMap.clear();
}
}
12 changes: 12 additions & 0 deletions packages/flame_tiled/test/tile_atlas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ void main() {
matchesGoldenFile('goldens/larger_atlas_component.png'),
);
});

test('clearing cache', () async {
await TiledAtlas.fromTiledMap(
simpleMap,
);

expect(TiledAtlas.atlasMap.isNotEmpty, true);

TiledAtlas.clearCache();

expect(TiledAtlas.atlasMap.isEmpty, true);
});
});

group('Single tileset map', () {
Expand Down

0 comments on commit d40fefc

Please sign in to comment.