mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
feat: Spine bridge package (#2530)
This PR introduces a bridge package for Spine. https://user-images.githubusercontent.com/744771/236058480-75c8212b-98e6-4e3b-834a-c1a9d4de31a8.mp4
This commit is contained in:
59
packages/flame_spine/example/lib/main.dart
Normal file
59
packages/flame_spine/example/lib/main.dart
Normal file
@ -0,0 +1,59 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/events.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame_spine/flame_spine.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await initSpineFlutter();
|
||||
runApp(const GameWidget.controlled(gameFactory: SpineExample.new));
|
||||
}
|
||||
|
||||
class SpineExample extends FlameGame with TapDetector {
|
||||
late final SpineComponent spineboy;
|
||||
|
||||
final states = [
|
||||
'walk',
|
||||
'aim',
|
||||
'death',
|
||||
'hoverboard',
|
||||
'idle',
|
||||
'jump',
|
||||
'portal',
|
||||
'run',
|
||||
'shoot',
|
||||
];
|
||||
|
||||
int _stateIndex = 0;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
// Load the Spineboy atlas and skeleton data from asset files
|
||||
// and create a SpineComponent from them, scaled down and
|
||||
// centered on the screen
|
||||
spineboy = await SpineComponent.fromAssets(
|
||||
atlasFile: 'assets/spineboy.atlas',
|
||||
skeletonFile: 'assets/spineboy-pro.skel',
|
||||
scale: Vector2(0.4, 0.4),
|
||||
anchor: Anchor.center,
|
||||
position: Vector2(size.x / 2, size.y / 2),
|
||||
);
|
||||
|
||||
// Set the "walk" animation on track 0 in looping mode
|
||||
spineboy.animationState.setAnimationByName(0, 'walk', true);
|
||||
await add(spineboy);
|
||||
}
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
_stateIndex = (_stateIndex + 1) % states.length;
|
||||
spineboy.animationState.setAnimationByName(0, states[_stateIndex], true);
|
||||
}
|
||||
|
||||
@override
|
||||
void onDetach() {
|
||||
// Dispose the native resources that have been loaded for spineboy.
|
||||
spineboy.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user