@@ -56,12 +56,89 @@ Import the plugin like this:
5656Load the TextureAtlas passing the path of the sprite sheet atlas file :
5757
5858` ` ` Dart
59- final atlas = await atlasFromAssets ('atlas_map.atlas');
59+ final atlas = await TexturePackerAtlas.load ('atlas_map.atlas');
6060` ` `
6161
6262
63- # ## Whitelist Images
63+ # ## Extension on Game
64+
65+ For convenience, there is also an extension on `Game` (and `FlameGame`)
66+ that allows you to load an atlas directly :
67+
68+ ` ` ` dart
69+ class MyGame extends FlameGame {
70+ @override
71+ Future<void> onLoad() async {
72+ final atlas = await atlasFromAssets('atlas_map.atlas');
73+ // ...
74+ }
75+ }
76+ ` ` `
77+
78+
79+ # ## Loading from a Package
80+
81+ To load an atlas from another Flutter package, use the `package` parameter :
82+
83+ ` ` ` Dart
84+ final atlas = await TexturePackerAtlas.load(
85+ 'atlas_map.atlas',
86+ package: 'my_assets_package',
87+ );
88+ ` ` `
89+
90+
91+ # ## Paths and Prefixes
92+
93+ By default, `TexturePackerAtlas.load` looks for files in `assets/images/`. This is controlled by the
94+ ` assetsPrefix` parameter, which defaults to `'images'`.
95+
96+
97+ # ### 1. Default usage (relative to `assets/images/`)
98+
99+ ` ` ` dart
100+ // Path: assets/images/hero.atlas
101+ final atlas = await TexturePackerAtlas.load('hero.atlas');
102+ ` ` `
103+
104+
105+ # ### 2. Custom prefix (relative to `assets/`)
106+
107+ ` ` ` dart
108+ // Path: assets/atlases/hero.atlas
109+ final atlas = await TexturePackerAtlas.load(
110+ 'hero.atlas',
111+ assetsPrefix: 'atlases',
112+ );
113+ ` ` `
64114
115+
116+ # ### 3. Full path (stripping standard prefix)
117+ If you provide a path that already includes the standard `assets/`
118+ or `images/` prefix, the library will automatically strip them to avoid duplication.
119+ This is particularly useful when working with full asset paths.
120+
121+ ` ` ` dart
122+ // Path: assets/images/mega_explosions.atlas
123+ final atlas = await TexturePackerAtlas.load(
124+ 'assets/images/mega_explosions.atlas',
125+ assetsPrefix: '',
126+ );
127+ ` ` `
128+
129+
130+ # ### 4. Automatic Package Detection
131+ If you provide a path that starts with `packages/package_name/...`,
132+ the library will automatically detect the package name
133+ and adjust the internal loading logic.
134+
135+ ` ` ` dart
136+ // Path: packages/my_assets_package/assets/images/heroes.atlas
137+ final atlas = await TexturePackerAtlas.load('packages/my_assets_package/assets/images/heroes.atlas');
138+ ` ` `
139+
140+
141+ # ## Whitelist Images
65142This is optional, but recommended to avoid loading every sprite from your texture pack into memory.
66143Use a list of relative paths to load only the Sprites you need into memory.
67144
@@ -76,12 +153,14 @@ final atlas = TexturePackerAtlas.fromAtlas(regions, whiteList: [
76153
77154
78155# ## File Storage
79-
80156If you are using file storage, grab your atlas file like this :
81157
82158` ` ` Dart
83159final documentsPath = (await getApplicationDocumentsDirectory()).path;
84- final atlas = await atlasFromStorage('$documentsPath/atlas_map.atlas');
160+ final atlas = await TexturePackerAtlas.load(
161+ '$documentsPath/atlas_map.atlas',
162+ fromStorage: true,
163+ );
85164` ` `
86165
87166Get a list of sprites ordered by their index, you can use the list to generate an animation :
@@ -96,6 +175,22 @@ final animation = SpriteAnimation.spriteList(
96175);
97176` ` `
98177
178+ Or use the convenience method `getAnimation` :
179+
180+ ` ` ` Dart
181+ final animation = atlas.getAnimation('robot_walk', stepTime: 0.1, loop: true);
182+ ` ` `
183+
184+ If your atlas contains multiple animations, load it once and reuse it :
185+
186+ ` ` ` Dart
187+ final atlas = await TexturePackerAtlas.load('atlas_map.atlas');
188+
189+ final walkAnim = atlas.getAnimation('robot_walk');
190+ final runAnim = atlas.getAnimation('robot_run');
191+ final jumpAnim = atlas.getAnimation('robot_jump', loop: false);
192+ ` ` `
193+
99194Get individual sprites by name :
100195
101196` ` ` Dart
@@ -112,8 +207,8 @@ final idleSprite = atlas.findSpriteByName('robot_idle')!;
112207| Allow Rotation | YES |
113208| Multiple Pages | YES |
114209| Use indices | YES |
115- | Strip whitespace X | NO |
116- | Strip whitespace Y | NO |
210+ | Strip whitespace X | YES |
211+ | Strip whitespace Y | YES |
117212
118213
119214# # Example
0 commit comments