Skip to content

Commit

Permalink
fix: Set SpriteButtonComponent sprites in onMount (#3327)
Browse files Browse the repository at this point in the history
Since it will be confusing for the user to have to call `super.onLoad`
last when they override `onLoad`, we move setting the `sprites` to
`onMount`.
  • Loading branch information
spydon authored Oct 3, 2024
1 parent ae230ff commit f36533e
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,29 @@ class SpriteButtonComponent extends SpriteGroupComponent<ButtonState>

set button(Sprite value) {
_button = value;
updateSprite(ButtonState.up, value);
if (isLoaded) {
updateSprite(ButtonState.up, value);
}
}

set buttonDown(Sprite value) {
_buttonDown = value;
updateSprite(ButtonState.down, value);
}

@override
void onLoad() {
super.onLoad();
sprites = {
ButtonState.up: button,
ButtonState.down: buttonDown,
};
if (isLoaded) {
updateSprite(ButtonState.down, value);
}
}

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

@override
Expand Down

0 comments on commit f36533e

Please sign in to comment.