mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 01:18:38 +08:00
Improving FlareComponent API and updating FlareFlutter dependency
This commit is contained in:
74
doc/examples/flare/lib/main_component.dart
Normal file
74
doc/examples/flare/lib/main_component.dart
Normal file
@ -0,0 +1,74 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/components/flare_component.dart';
|
||||
import 'package:flame/text_config.dart';
|
||||
import 'package:flame/position.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final game = MyGame();
|
||||
runApp(game.widget);
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame with TapDetector, DoubleTapDetector {
|
||||
final TextConfig fpsTextConfig =
|
||||
const TextConfig(color: const Color(0xFFFFFFFF));
|
||||
|
||||
final paint = Paint()..color = const Color(0xFFE5E5E5E5);
|
||||
final List<String> _animations = ["Stand", "Wave", "Jump", "Dance"];
|
||||
int _currentAnimation = 0;
|
||||
FlareComponent flareComponent;
|
||||
|
||||
bool loaded = false;
|
||||
|
||||
MyGame() {
|
||||
_start();
|
||||
}
|
||||
|
||||
@override
|
||||
bool debugMode() => true;
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
cycleAnimation();
|
||||
}
|
||||
|
||||
@override
|
||||
void onDoubleTap() {
|
||||
flareComponent.width += 10;
|
||||
flareComponent.height += 10;
|
||||
|
||||
flareComponent.x -= 10;
|
||||
flareComponent.y -= 10;
|
||||
}
|
||||
|
||||
void cycleAnimation() {
|
||||
if (_currentAnimation == 3) {
|
||||
_currentAnimation = 0;
|
||||
} else {
|
||||
_currentAnimation++;
|
||||
}
|
||||
flareComponent.updateAnimation(_animations[_currentAnimation]);
|
||||
}
|
||||
|
||||
void _start() async {
|
||||
flareComponent = FlareComponent("assets/Bob_Minion.flr", "Stand", 306, 228);
|
||||
flareComponent.x = 50;
|
||||
flareComponent.y = 240;
|
||||
add(flareComponent);
|
||||
}
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
|
||||
if (debugMode()) {
|
||||
fpsTextConfig.render(canvas, fps(120).toString(), Position(0, 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user