mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Fixing gestures conflicts and adding a gestures example
This commit is contained in:
committed by
Erick (CptBlackPixel)
parent
655a70b0a6
commit
6f44e0514b
50
doc/examples/gestures/lib/main.dart
Normal file
50
doc/examples/gestures/lib/main.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flame/game.dart';
|
||||
|
||||
void main() {
|
||||
final game = MyGame();
|
||||
runApp(game.widget);
|
||||
}
|
||||
|
||||
class MyGame extends Game {
|
||||
final _whitePaint = Paint()..color = const Color(0xFFFFFFFF);
|
||||
final _bluePaint = Paint()..color = const Color(0xFF0000FF);
|
||||
final _greenPaint = Paint()..color = const Color(0xFF00FF00);
|
||||
|
||||
Paint _paint;
|
||||
|
||||
Rect _rect = const Rect.fromLTWH(50, 50, 50, 50);
|
||||
|
||||
MyGame() {
|
||||
_paint = _whitePaint;
|
||||
}
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
_paint = _paint == _whitePaint ? _bluePaint : _whitePaint;
|
||||
}
|
||||
|
||||
@override
|
||||
bool useDoubleTapDetectors() => true;
|
||||
|
||||
@override
|
||||
void onDoubleTap() {
|
||||
_paint = _greenPaint;
|
||||
}
|
||||
|
||||
@override
|
||||
bool usePanDetectors() => true;
|
||||
|
||||
@override
|
||||
void onPanUpdate(DragUpdateDetails details) {
|
||||
_rect = _rect.translate(details.delta.dx, details.delta.dy);
|
||||
}
|
||||
|
||||
@override
|
||||
void update(double dt) {}
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
canvas.drawRect(_rect, _paint);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user