Last updated:
0 purchases
flame composition rendering
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
}
}
copied to clipboard
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);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.