0

Can Flutter Flame render Widget inside game world like other components? (not overlay widget).

(I want to apply forge2d physic to widget and I'm trying to do it with Flame.)

dante
  • 984
  • 3
  • 10
  • 24
  • 1
    You need to use either the overlays API or a Flutter stack to do this. Why do you not want to use the overlays API? Flutter widgets are not Flame components so they can not be added directly to the component tree. – spydon Sep 26 '21 at 18:07
  • Thanks. I only want to use physics to create animation so I will use forge2d directly instead. – dante Sep 27 '21 at 02:46

1 Answers1

6

You can not, you can only do it through the overlay system or use a Stack, but the widgets are never "in" the game, but on top of the game. The game can only have Flame Components added directly to it.

You can still interact with the overlay widgets from the game though, like this for example: https://twitter.com/spydon/status/1417832832693673988

In that example I simply wrap the ElevatedButton with Positioned and Transform and then I updated those with the values from corresponding BodyComponents.

spydon
  • 9,372
  • 6
  • 33
  • 63
  • Hi @spydon do you have a sample of this somewhere? Thanks – Chris G. Apr 12 '22 at 06:20
  • 1
    @ChrisG. this tweet https://twitter.com/spyd0n/status/1417832832693673988 is running this example: https://github.com/flame-engine/flame/blob/main/packages/flame_forge2d/example/lib/widget_sample.dart – spydon Apr 12 '22 at 07:13
  • @spydon the link gives 404 – sonic Sep 20 '22 at 09:57
  • https://twitter.com/spydon/status/1417832832693673988 https://examples.flame-engine.org/#/flame_forge2d_Widgets These links should work (get to the code by pressing < > in the top right corner) – spydon Sep 20 '22 at 14:21