Files
flame/examples/lib/stories/input/double_tap_callbacks_example.dart
Luan Nico b79fee0ae2 chore: Update min Dart constraint to 3.8 (#3676)
Update min Dart constraint to 3.8, which will enable us to use the
fancier collection literals.

This requires bumping the min Flutter version as well:

<img width="1892" height="1122" alt="image"
src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85"
/>
2025-08-10 12:42:31 -04:00

66 lines
1.6 KiB
Dart

import 'package:examples/commons/ember.dart';
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
class DoubleTapCallbacksExample extends FlameGame with DoubleTapCallbacks {
static const String description = '''
In this example, we show how you can use the `DoubleTapCallbacks` mixin on
a `Component`. Double tap Ember and see her color changing.
The example also adds white circles when double-tapping on the game area.
''';
@override
Future<void> onLoad() async {
children.register<DoubleTappableEmber>();
}
@override
void onGameResize(Vector2 size) {
children.query<DoubleTappableEmber>().forEach(
(element) => element.removeFromParent(),
);
add(DoubleTappableEmber(position: size / 2));
super.onGameResize(size);
}
@override
void onDoubleTapDown(DoubleTapDownEvent event) {
add(
CircleComponent(
radius: 30,
position: event.localPosition,
anchor: Anchor.center,
),
);
}
}
class DoubleTappableEmber extends Ember with DoubleTapCallbacks {
@override
bool debugMode = true;
DoubleTappableEmber({Vector2? position})
: super(
position: position ?? Vector2.all(100),
size: Vector2.all(100),
);
@override
void onDoubleTapUp(DoubleTapEvent event) {
debugColor = Colors.greenAccent;
}
@override
void onDoubleTapCancel(DoubleTapCancelEvent event) {
debugColor = Colors.red;
}
@override
void onDoubleTapDown(DoubleTapDownEvent event) {
debugColor = Colors.blue;
}
}