mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 08:27:36 +08:00
docs: Fix naming of drag- and tap-callbacks examples (#2873)
Fix naming of drag- and tap-callbacks examples
This commit is contained in:
45
examples/lib/stories/input/drag_callbacks_example.dart
Normal file
45
examples/lib/stories/input/drag_callbacks_example.dart
Normal file
@ -0,0 +1,45 @@
|
||||
import 'package:examples/commons/ember.dart';
|
||||
import 'package:flame/events.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flutter/material.dart' show Colors;
|
||||
|
||||
class DragCallbacksExample extends FlameGame {
|
||||
static const String description = '''
|
||||
In this example we show you can use the `DragCallbacks` mixin on
|
||||
`PositionComponent`s. Drag around the Embers and see their position
|
||||
changing.
|
||||
''';
|
||||
|
||||
DragCallbacksExample({required this.zoom});
|
||||
|
||||
final double zoom;
|
||||
late final DraggableEmber square;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
camera.viewfinder.zoom = zoom;
|
||||
world.add(square = DraggableEmber());
|
||||
world.add(DraggableEmber()..y = 350);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this component does not consider the possibility of multiple
|
||||
// simultaneous drags with different pointerIds.
|
||||
class DraggableEmber extends Ember with DragCallbacks {
|
||||
@override
|
||||
bool debugMode = true;
|
||||
|
||||
DraggableEmber({super.position}) : super(size: Vector2.all(100));
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
debugColor = isDragged ? Colors.greenAccent : Colors.purple;
|
||||
}
|
||||
|
||||
@override
|
||||
void onDragUpdate(DragUpdateEvent event) {
|
||||
event.continuePropagation = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user