3

I'm making a flutter game with Flame and i have a problem implementing the controllers. The controllers are basically a joystick and a button atack. To the joystick i need the panStart, panUpdate and panEnd gestures, and to the attack button onTapUp and onTapDown. But i can't do both at same time, only a gesture at once

MultiTapGestureRecognizer tapper = MultiTapGestureRecognizer();
PanGestureRecognizer panGesture = PanGestureRecognizer();

panGesture.onEnd = game.onPanEnd;
panGesture.onUpdate = game.onPanUpdate;
panGesture.onStart = game.onPanStart;
panGesture.onCancel = game.onPanCancel;
tapper.onTapDown = game.onTapDown;
tapper.onTapUp = game.onTapUp;
tapper.onTapCancel = game.onTapCancel;
flameUtil.addGestureRecognizer(tapper);
flameUtil.addGestureRecognizer(panGesture);
Luan Nico
  • 5,376
  • 2
  • 30
  • 60

1 Answers1

1

Instead of using the GestureRecognizers, use the PanDetector and TapDetector mixins directly on your game class and override the methods that you need.

class MyGame extends BaseGame with TapDetector, PanDetector {

  MyGame();

  @override
  void onTap() {}

  @override
  void onTapCancel() {}

  @override
  void onTapDown(TapDownDetails details) {}

  @override
  void onTapUp(TapUpDetails details) {}

  @override
  void onPanDown(DragDownDetails details) {}

  @override
  void onPanStart(DragStartDetails details) {}

  @override
  void onPanUpdate(DragUpdateDetails details) {}

  @override
  void onPanEnd(DragEndDetails details) {}

  @override
  void onPanCancel() {}
}
spydon
  • 9,372
  • 6
  • 33
  • 63