mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 16:36:57 +08:00
Update min Dart constraint to 3.8, which will enable us to use the fancier collection literals. This requires bumping the min Flutter version as well: <img width="1892" height="1122" alt="image" src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85" />
53 lines
1.2 KiB
Dart
53 lines
1.2 KiB
Dart
import 'package:flame/events.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame_rive/flame_rive.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
runApp(const GameWidget.controlled(gameFactory: RiveExampleGame.new));
|
|
}
|
|
|
|
class RiveExampleGame extends FlameGame {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final skillsArtboard = await loadArtboard(
|
|
RiveFile.asset('assets/skills.riv'),
|
|
);
|
|
add(SkillsAnimationComponent(skillsArtboard));
|
|
}
|
|
}
|
|
|
|
class SkillsAnimationComponent extends RiveComponent with TapCallbacks {
|
|
SkillsAnimationComponent(Artboard artboard) : super(artboard: artboard);
|
|
|
|
SMIInput<double>? _levelInput;
|
|
|
|
@override
|
|
void onGameResize(Vector2 size) {
|
|
super.onGameResize(size);
|
|
this.size = size;
|
|
}
|
|
|
|
@override
|
|
void onLoad() {
|
|
final controller = StateMachineController.fromArtboard(
|
|
artboard,
|
|
"Designer's Test",
|
|
);
|
|
if (controller != null) {
|
|
artboard.addController(controller);
|
|
_levelInput = controller.findInput<double>('Level');
|
|
_levelInput?.value = 0;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onTapDown(TapDownEvent event) {
|
|
final levelInput = _levelInput;
|
|
if (levelInput == null) {
|
|
return;
|
|
}
|
|
levelInput.value = (levelInput.value + 1) % 3;
|
|
}
|
|
}
|