Closed ycfay closed 1 month ago
Can you do print(animations);
after you have prepared them?
print(animations)
the result:
flutter: {PlayerState.attack_down: Instance of 'SpriteAnimation', PlayerState.attack_down_left: Instance of 'SpriteAnimation', PlayerState.attack_down_right: Instance of 'SpriteAnimation', PlayerState.attack_left: Instance of 'SpriteAnimation', PlayerState.attack_right: Instance of 'SpriteAnimation', PlayerState.attack_up: Instance of 'SpriteAnimation', PlayerState.attack_up_left: Instance of 'SpriteAnimation', PlayerState.attack_up_right: Instance of 'SpriteAnimation', PlayerState.idle_up: Instance of 'SpriteAnimation', PlayerState.idle_down: Instance of 'SpriteAnimation', PlayerState.idle_left: Instance of 'SpriteAnimation', PlayerState.idle_right: Instance of 'SpriteAnimation', PlayerState.idle_down_left: Instance of 'SpriteAnimation', PlayerState.idle_down_right: Instance of 'SpriteAnimation', PlayerState.idle_up_left: Instance of 'SpriteAnimation', PlayerState.idle_up_right: Instance of 'SpriteAnimation', PlayerState.run_down: Instance of 'SpriteAnimation', PlayerState.run_down_left: Instance of 'SpriteAnimation', PlayerState.run_down_right: Instance of 'SpriteAnimation', PlayerState.run_left: Instance of 'SpriteAnimation', PlayerState.run_right: Instance of 'SpriteAnimation', PlayerState.run_up_left: Instance of 'SpriteAnimation', PlayerState.run_up_right: Instance of 'SpriteAnimation', PlayerState.run_up: Instance of 'SpriteAnimation', PlayerState.death_down: Instance of 'SpriteAnimation', PlayerState.death_down_left: Instance of 'SpriteAnimation', PlayerState.death_down_right: Instance of 'SpriteAnimation', PlayerState.death_left: Instance of 'SpriteAnimation', PlayerState.death_right: Instance of 'SpriteAnimation', PlayerState.death_up: Instance of 'SpriteAnimation', PlayerState.death_up_left: Instance of 'SpriteAnimation', PlayerState.death_up_right: Instance of 'SpriteAnimation'}
the base class
class Monster extends SpriteAnimationGroupComponent<PlayerState>
with HasGameRef<Test8Game>, CollisionCallbacks {
@override
Future<void> onLoad() async {
}
Future<void> prepareAnimations() async {}
}
Which version of Flame are you on?
flame: ^1.18.0 flame_texturepacker: ^4.0.1
I think it's the components haven't been adapted yet!
I think it's the components haven't been adapted yet!
They should be fine, the output are just normal SpriteAnimation
instances which is what SpriteGroupComponent
handles. Can you provide a repository (it can be private, but you'd have to invite me) with a minimal reproducible example, containing the atlas etc?
The code has been uploaded to GitHub: https://github.com/ycfay/tsdm.git
Tkx
Now I see what your problem is, you have to use the animations
setter, not mutate the existing map since the animations then won't get any animation tickers etc. So do this instead:
@override
Future<void> prepareAnimations() async {
// The size I would put in the constructor
size = Vector2.all(60);
final newAnimations = {};
for (var action in PlayerState.values) {
final sprites = atlas.findSpritesByName(action.name);
if (sprites.isNotEmpty) {
SpriteAnimation animation = SpriteAnimation.spriteList(
sprites,
stepTime: 0.2,
loop: true,
);
newAnimations.addAll({action: animation});
}
}
animations = newAnimations;
current = PlayerState.idle_down;
}
Disallowed these mutations in #3183 to avoid confusion in the future.
It worked, thanks!
Problem to solve
the code
i must
add(SpriteAnimationComponent...)
to be able to work, which is not what I was hoping for!Proposal
I hope to be able to support SpriteAnimationGroupComponent.
More information
No response
Other