2

Can flutter flame (https://flame-engine.org/) be used to create a "flame widget" which can be used within a Flutter app? (i.e. as opposed to having a full flame game, for which you might do flutter widget overlays)

For example say you had a Flutter app, but say within Screen/Page XXX one wanted to have a clock widget (analogue). So in this case in terms of in Flutter how you would create the graphics for an analogue clock could Flame be used for this?

If yes are there any examples of how to do this? (be trying to find some with no success so far, so not sure).

Greg
  • 34,042
  • 79
  • 253
  • 454

1 Answers1

4

All Flame games are added to the GameWidget, and this GameWidget can be put anywhere inside of your Flutter widget tree.

Do note that if you don't want your game to be reset when the widget tree is rebuilt, keep a reference to is outside of the GameWidget.

final game = YourGame();

/// Your flutter widget tree
...
    child: GameWidget(game: game);
...

For the specific example you had with an analogue clock it might be possible to use a SpriteAnimationWidget.

spydon
  • 9,372
  • 6
  • 33
  • 63
  • thanks for the reply - offhand for a something like an analog clock, perhaps assume you might want it to have some touch/gesture points on the hands say to feed back to the main app, would starting to dive into flame be what you'd recommend? (as opposed to starting with flutter canvas?) i.e. flame seems an ok fit? (as opposed to overkill) – Greg Jan 27 '22 at 21:44
  • 2
    Since Flutter has tree shaking I think Flame would do just fine here, but I'm obviously not unbiased. ;) – spydon Jan 27 '22 at 23:09