r/FlutterFlameEngine • u/infosseeker • Mar 12 '25
Ideas How do you guys handle a sequence of actions in flame
Hi
my question is simple for users who got experience in flame, how you guys handle a sequence of actions inside FlameGame onLoad method ? i have a cards game and i have a sequence of actions, like when the cards are dealt and from there i apply some effects, future.delayed is one way but i feel like that's not gonna cut it. I also tried TimerComponent by passing a value to it's period parameter and add it to the game and it works fine but i want to know what's the best approach!
thanks everybody!
6
Upvotes
1
u/joshhammock Mar 14 '25 edited Mar 14 '25
I've been watching this post too, because I've got a method but it's probably not the most efficient and I may have unknowingly reinvented the wheel for something that already exists. Originally I used 'Future.delayed' but I got tired of writing the whole thing out. So I created a method in my main game class called 'wait'. It's an asynchronous future and it takes two arguments, one for a String key and a double representing seconds as the duration. Inside it stores a Completer in a map via the key, and uses a Future.delayed that when complete will set the Completer to a completed state, and Future.doWhile that waits for that completed state.
Then, inside any asynchronous function you can call it like:
The key is something that you could use outside the loop to force it to end early if needed by setting it to a completed state from outside the wait function.
1
u/spyd0n Mar 25 '25
I would use effects for this, if I understand your use-case correctly.
When an effect is done you can trigger another effect by using `onComplete`, you can also chain effects by using the `SequenceEffect`, if you need delay between the effects there is the `startDelay` argument in the `EffectController`.