flame_flare 1.5.4+1 copy "flame_flare: ^1.5.4+1" to clipboard
flame_flare: ^1.5.4+1 copied to clipboard

discontinuedreplaced by: flame_rive

This packages allows you to use flare animations into a Flame game.

example/lib/main.dart

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flame_flare/flame_flare.dart';
import 'package:flare_flutter/flare_controls.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(GameWidget(game: MyGame()));
}

class MyGame extends FlameGame with TapDetector, DoubleTapDetector {
  final paint = Paint()..color = const Color(0xFFE5E5E5);
  final List<String> _animations = ['Wave', 'Dance'];

  int _currentAnimation = 0;
  final MinionController minionController = MinionController();

  late final MinionComponent minionComponent;

  @override
  Future<void> onLoad() async {
    add(BGComponent());
    add(minionComponent = MinionComponent(minionController));

    minionController.playStand();
  }

  @override
  void onTap() {
    minionController.playJump();
  }

  @override
  void onDoubleTap() {
    cycleAnimation();
  }

  void cycleAnimation() {
    _currentAnimation = (_currentAnimation + 1) % _animations.length;
    minionController.play(_animations[_currentAnimation]);
  }
}

class MinionController extends FlareControls {
  void playStand() {
    play('Stand');
  }

  void playDance() {
    play('Dance');
  }

  void playJump() {
    play('Jump');
  }

  void playWave() {
    play('Wave');
  }
}

class MinionComponent extends FlareActorComponent {
  MinionController minionController;

  MinionComponent(this.minionController)
      : super(
          FlareActorAnimation(
            'assets/Bob_Minion.flr',
            controller: minionController,
            fit: BoxFit.scaleDown,
          ),
          size: Vector2.all(300),
        );

  @override
  void render(Canvas canvas) {
    final rect = Rect.fromLTWH(x, y, width, height);
    final paint = Paint()..color = const Color(0xFFfafbfc);
    canvas.drawRect(rect, paint);
    super.render(canvas);
  }

  @override
  void onGameResize(Vector2 size) {
    super.onGameResize(size);
    position = (size - this.size) / 2;
  }
}

class BGComponent extends Component with HasGameRef {
  static final paint = BasicPalette.white.paint();

  @override
  void render(Canvas canvas) {
    canvas.drawRect(gameRef.size.toRect(), paint);
  }
}
25
likes
160
pub points
17%
popularity

Publisher

verified publisherflame-engine.org

This packages allows you to use flare animations into a Flame game.

Repository (GitHub)
View/report issues

Documentation

API reference

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

MIT (license)

Dependencies

flame, flare_flutter, flutter

More

Packages that depend on flame_flare