mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
* Fix rendering of children * Game loop handles other restore * Properly propagate onMount and onRemove to children * Use BaseGame on gestures to minimize confusion * Fix linting * All children don't need preparation * Add composability example * gameRef might not be defined * Add mustCallSuper * isMounted on game * Remove unused gameRef argument * Made isMounted only modifiable by the component * Move dartdoc to public isMounted * Fix formatting
54 lines
1008 B
Dart
54 lines
1008 B
Dart
import 'package:flame/game.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flame/gestures.dart';
|
|
import 'package:flame/palette.dart';
|
|
|
|
void main() {
|
|
runApp(
|
|
GameWidget(
|
|
game: MyGame(),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Includes an example including advanced detectors
|
|
class MyGame extends BaseGame with MultiTouchTapDetector {
|
|
final _whitePaint = BasicPalette.white.paint;
|
|
|
|
Paint _paint;
|
|
|
|
final Map<int, Rect> _taps = {};
|
|
|
|
MyGame() {
|
|
_paint = _whitePaint;
|
|
}
|
|
|
|
@override
|
|
void onTapDown(int pointerId, TapDownDetails details) {
|
|
_taps[pointerId] = Rect.fromLTWH(
|
|
details.globalPosition.dx,
|
|
details.globalPosition.dy,
|
|
50,
|
|
50,
|
|
);
|
|
}
|
|
|
|
@override
|
|
void onTapUp(int pointerId, _) {
|
|
_taps.remove(pointerId);
|
|
}
|
|
|
|
@override
|
|
void onTapCancel(int pointerId) {
|
|
_taps.remove(pointerId);
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
super.render(canvas);
|
|
_taps.values.forEach((rect) {
|
|
canvas.drawRect(rect, _paint);
|
|
});
|
|
}
|
|
}
|