mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +08:00
* Refactor joystick * Fix directional tests * Joystick example * Any PositionComponent can be used as knob and background * Add MarginButtonComponent * Fix JoystickExample * Update joystick docs * Fix joystick direction tests * Fix effect tests * Fix analyze issue * Update docs * Update docs * Move joystick to input export * Update packages/flame/lib/src/geometry/shape.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Add test and description for screenAngle * Update examples/lib/stories/controls/joystick_player.dart Co-authored-by: Erick <erickzanardoo@gmail.com> * Update doc/input.md Co-authored-by: Erick <erickzanardoo@gmail.com> * controls -> input in examples to align with export file * controls -> input * Add simple joystick example * Fix imports * velocity -> relativeDelta Co-authored-by: Luan Nico <luanpotter27@gmail.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
49 lines
1.1 KiB
Dart
49 lines
1.1 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
|
|
class ZoomGame extends BaseGame with ScrollDetector, ScaleDetector {
|
|
final Vector2 viewportResolution;
|
|
late SpriteComponent flame;
|
|
|
|
Vector2? lastScale;
|
|
|
|
ZoomGame({
|
|
required this.viewportResolution,
|
|
});
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final flameSprite = await loadSprite('flame.png');
|
|
|
|
viewport = FixedResolutionViewport(viewportResolution);
|
|
camera.setRelativeOffset(Anchor.center);
|
|
camera.speed = 1;
|
|
|
|
final flameSize = Vector2(149, 211);
|
|
add(
|
|
flame = SpriteComponent(
|
|
sprite: flameSprite,
|
|
size: flameSize,
|
|
)..anchor = Anchor.center,
|
|
);
|
|
}
|
|
|
|
static const zoomPerScrollUnit = 0.001;
|
|
@override
|
|
void onScroll(PointerScrollInfo info) {
|
|
camera.zoom += info.scrollDelta.game.y * zoomPerScrollUnit;
|
|
}
|
|
|
|
@override
|
|
void onScaleUpdate(ScaleUpdateInfo info) {
|
|
final scale = lastScale;
|
|
if (scale != null) {
|
|
final delta = info.scale.game - scale;
|
|
camera.zoom += delta.y;
|
|
}
|
|
|
|
lastScale = info.scale.game;
|
|
}
|
|
}
|