我正在开发一个使用火焰和颤动的简单游戏。我正在学习本教程:Create a Mobile Game with Flutter and Flame – Beginner Tutorial
但在我添加了以下教程行的代码后:
flameUtil.addGestureRecognizer(tapper);
显示下划线,并且onTap
函数不起作用。
发布于 2021-02-08 04:53:30
flutter-flame
库的API在不断发展,上面教程中的解决方案可能不再有效。
我在重新实现此演示文稿中的示例时遇到了一些困难:https://www.youtube.com/watch?v=sFpjEH-ok2s,因此您并不孤单:-)
像0.23.0
这样的较新版本的flutter-flame
需要将TapDetector
混合添加到您的BaseGame
类中,如下所示:
class MyBaseGame extends BaseGame with TapDetector, DoubleTapDetector {
@override
void onTapDown(_) {
add(RenderedTimeComponent(Timer(1)..start()));
}
@override
void onDoubleTap() {
add(RenderedTimeComponent(Timer(5)..start()));
}
}
多亏了这一点,你的BoxGame初始化代码就是:
BoxGame game = BoxGame();
runApp(game.widget);
不需要声明Util
和TapGestureRecognizer
。
https://stackoverflow.com/questions/64120397
复制相似问题