mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 08:27:36 +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>
70 lines
1.7 KiB
Dart
70 lines
1.7 KiB
Dart
import 'package:flame/effects.dart';
|
|
import 'package:flame/extensions.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../commons/square_component.dart';
|
|
|
|
final green = Paint()..color = const Color(0xAA338833);
|
|
|
|
class SequenceEffectGame extends BaseGame with TapDetector {
|
|
late SquareComponent greenSquare;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
greenSquare = SquareComponent()
|
|
..paint = green
|
|
..position.setValues(100, 100);
|
|
add(greenSquare);
|
|
}
|
|
|
|
@override
|
|
void onTapUp(TapUpInfo info) {
|
|
final currentTap = info.eventPosition.game;
|
|
greenSquare.clearEffects();
|
|
|
|
final move1 = MoveEffect(
|
|
path: [currentTap],
|
|
speed: 250.0,
|
|
curve: Curves.bounceInOut,
|
|
isAlternating: true,
|
|
);
|
|
|
|
final move2 = MoveEffect(
|
|
path: [
|
|
currentTap + Vector2(0, 50),
|
|
currentTap + Vector2(-50, -50),
|
|
currentTap + Vector2(50, 0),
|
|
],
|
|
speed: 150.0,
|
|
curve: Curves.easeIn,
|
|
);
|
|
|
|
final scale = ScaleEffect(
|
|
size: currentTap,
|
|
speed: 100.0,
|
|
curve: Curves.easeInCubic,
|
|
);
|
|
|
|
final rotate = RotateEffect(
|
|
angle: currentTap.angleTo(Vector2.all(100)),
|
|
duration: 0.8,
|
|
curve: Curves.decelerate,
|
|
);
|
|
|
|
final combination = CombinedEffect(
|
|
effects: [move2, rotate],
|
|
isAlternating: true,
|
|
onComplete: () => print('combination complete'),
|
|
);
|
|
|
|
final sequence = SequenceEffect(
|
|
effects: [move1, scale, combination],
|
|
isAlternating: true,
|
|
);
|
|
sequence.onComplete = () => print('sequence complete');
|
|
greenSquare.addEffect(sequence);
|
|
}
|
|
}
|