flame_spine 0.2.0+1 copy "flame_spine: ^0.2.0+1" to clipboard
flame_spine: ^0.2.0+1 copied to clipboard

Spine support for the Flame game engine. This uses the spine_flutter package and provides wrappers and components to be used inside Flame.

example/lib/main.dart

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();
  }
}
4
likes
125
pub points
87%
popularity

Publisher

verified publisherflame-engine.org

Spine support for the Flame game engine. This uses the spine_flutter package and provides wrappers and components to be used inside Flame.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

unknown (LICENSE)

Dependencies

collection, flame, flutter, spine_flutter

More

Packages that depend on flame_spine