gpt4 book ai didi

flutter - 如何检测带有 flutter/火焰的游戏中的滑动

转载 作者:行者123 更新时间:2023-12-03 02:46:47 25 4
gpt4 key购买 nike

我想制作一款火热的游戏。对于这个游戏,我想检测滑动。

我可以在教程的帮助下实现点击识别。但是我无法通过滑动检测来实现它。

我的主要 Taprecognition 看起来像这样:我的主要功能是

void main() async{
Util flameUtil = Util();
await flameUtil.fullScreen();
await flameUtil.setOrientation(DeviceOrientation.portraitUp);

GameManager game = GameManager();
runApp(game.widget);

TapGestureRecognizer tapper = TapGestureRecognizer();
tapper.onTapDown = game.onTapDown;
flameUtil.addGestureRecognizer(tapper);
}

在我的 GameManager 类中我有:

class GameMAnager extends Game{
// a few methods like update, render and constructor
void onTapDown(TapDownDetails d) {
if (bgRect.contains(d.globalPosition)) { //bgRect is the background rectangle, so the tap works on the whole screen
player.onTapDown();
}
}

我的播放器类包含:

  void onTapDown(){
rotate();
}

现在我想将其更改为沿滑动方向而不是 onTapDown 旋转。我试图以某种方式添加

  GestureDetector swiper = GestureDetector();
swiper.onPanUpdate = game.onPanUpdate;

到我的主要和

  void onPanUpdate() {

}

到我的 gameManager 类。但是我找不到任何类似于 TapDownDetails 的平移。

对此有什么建议吗?

我看到一些帮助将小部件包装在 GestureDetector 中并像这样使用它:

GestureDetector(onPanUpdate: (details) {
if (details.delta.dx > 0) {
// swiping in right direction
}
});

但我无法让它在我的项目中发挥作用。

最佳答案

您可以使用 Horizo​​ntalDragGestureDetector(如果您需要两个轴,则可以使用 PanGestureRecognizer)在您的主要方法中使用以下内容

HorizontalDragGestureRecognizer tapper = HorizontalDragGestureRecognizer();
tapper.onUpdate = game.dragUpdate;

然后在您的 GameManager 中执行以下操作

void dragUpdate(DragUpdateDetails d) {
// using d.delta you can then track the movement and implement your rotation updade here
}

这应该可以解决问题 :D

关于flutter - 如何检测带有 flutter/火焰的游戏中的滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58578343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com