Skip to content

Commit

Permalink
fix: SpriteButtonComponent to initialize sprites in onLoad (#3302)
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet-739 authored Sep 20, 2024
1 parent d4d9cb6 commit 1204216
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ class SpriteButtonComponent extends SpriteGroupComponent<ButtonState>
}

@override
void onMount() {
assert(
_button != null,
'The button sprite has to be set either in onLoad or in the constructor',
);
void onLoad() {
super.onLoad();
sprites = {
ButtonState.up: button,
ButtonState.down: buttonDown,
};
}

@override
void onMount() {
super.onMount();
assert(
_button != null,
'The button sprite has to be set either in onLoad or in the constructor',
);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class SpriteGroupComponent<T> extends PositionComponent

/// Updates the sprite for the given key.
void updateSprite(T key, Sprite sprite) {
_sprites![key] = sprite;
assert(_sprites != null, 'Sprites map is not yet initialized');
_sprites?[key] = sprite;
_resizeToSprite();
}

Expand Down

0 comments on commit 1204216

Please sign in to comment.