Reputation: 31
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);
Upvotes: 3
Views: 848
Reputation: 11562
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() {}
}
Upvotes: 1