我有一些问题。我正在研究在 Expanded Widget 中使用 Flame Engine 作为更大应用程序一部分的应用程序。因此 Flame 仅用作按钮的图形表示和交互。
现在,理论上:
至于代码,我在应用程序中的计数器如下所示:
...
Column(
children: [
Text('show 1'),
Text(_firstCounter.toString())
],
),
...
void CountersAndOthers() async {
if(_gameInProgress == true){ return; }
_gameInProgress = true;
_testGame = new TestGame();
_firstCounter = _testGame.counterNumeroUno;
}
在 Flame 中,它是一个简单的 onTap() 函数,它增加了 int 计数器:
@override
void onTap() async {
counter++;
print(counter);
jump();
_timer.start();
}
在不使用任何状态管理库的情况下,您可以将小部件的回调函数传递给扩展的 Flame 游戏类,并在onTap
调用Flame 时通过它更新小部件的状态。
这是相反的方式,将您的游戏类传递给导航按钮并调用您在火焰游戏中创建的函数,该函数将对您的按钮按下做出反应。
根据您的应用程序的结构,有多种方法可以做到这一点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句