flame_composition_rendering 0.1.0-dev.5
flame_composition_rendering: ^0.1.0-dev.5 copied to clipboard

Plugin for integrating composition rendering into the Flame game engine.

Pub Version Pub Version

Usage FlamePluginComponent #

A simple usage example:

import 'package:composition_rendering/scene.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame_composition_rendering/flame_plugin.dart';
import 'package:flutter/widgets.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(
    GameWidget(
      game: ExampleLauncher(),
    ),
  );
}

class ExampleLauncher extends BaseGame {
  final FlamePluginComponent plugin = FlamePluginComponent();

  ExampleLauncher() {
    plugin.scene = GameScene();
  }

  @override
  Future<void> onLoad() async {
    await Flame.images.loadAll([
      'bg.jpg',
    ]);
    await add(plugin);
  }
}

class GameScene extends Scene {
  @override
  void init() {
    // your play scene
  }
}

Usage SpriteBatchComponent #

Alternative SpriteBatch for Flame. Rendering three sprites in one call Canvas.drawRawAtlas

import 'package:flame/components.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame_composition_rendering/flame_composition_rendering.dart';
import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  Flame.device.fullScreen();
  Flame.device.setLandscape();

  runApp(
    GameWidget(
      game: ExampleLauncher(),
    ),
  );
}

class ExampleLauncher extends BaseGame {
  @override
  Future<void> onLoad() async {
    await Flame.images.loadAll(['crab.png']);
    await add(SpriteBatchComponent());
  }

  @override
  Color backgroundColor() => const Color(0xFFFFFFFF);
}

class SpriteBatchComponent extends FlameBatchComponent {
  late final image;
  late final sprite;

  @override
  Future<void>? onLoad() {
    image = Flame.images.fromCache('crab.png');
    sprite = Sprite(image);
  }

  @override
  void beginBatch() {
    drawSprite(sprite, x: 100, y: 200);
    drawSprite(sprite, x: 200, y: 200);
    drawSprite(sprite, x: 300, y: 200);
    drawSpriteFromComponents(sprite, x: 400, y: 100, rotation: 0.4, scale: 0.6);
  }
}
1
likes
100
pub points
6%
popularity

Plugin for integrating composition rendering into the Flame game engine.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

composition_rendering, flame, flutter, vector_math

More

Packages that depend on flame_composition_rendering