flame 0.18.2 copy "flame: ^0.18.2" to clipboard
flame: ^0.18.2 copied to clipboard

outdated

A minimalist Flutter game engine, provides a nice set of somewhat independent modules you can choose from.

example/lib/main.dart

import 'dart:math' as math;
import 'dart:ui';

import 'package:flame/anchor.dart';
import 'package:flame/components/component.dart';
import 'package:flame/components/mixins/has_game_ref.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyGame().widget);

class Palette {
  static const PaletteEntry white = BasicPalette.white;
  static const PaletteEntry red = PaletteEntry(Color(0xFFFF0000));
  static const PaletteEntry blue = PaletteEntry(Color(0xFF0000FF));
}

class Square extends PositionComponent with HasGameRef<MyGame> {
  static const SPEED = 0.25;

  @override
  void resize(Size size) {
    x = size.width / 2;
    y = size.height / 2;
  }

  @override
  void render(Canvas c) {
    prepareCanvas(c);

    c.drawRect(Rect.fromLTWH(0, 0, width, height), Palette.white.paint);
    c.drawRect(const Rect.fromLTWH(0, 0, 3, 3), Palette.red.paint);
    c.drawRect(Rect.fromLTWH(width / 2, height / 2, 3, 3), Palette.blue.paint);
  }

  @override
  void update(double t) {
    angle += SPEED * t;
    angle %= 2 * math.pi;
  }

  @override
  void onMount() {
    width = height = gameRef.squareSize;
    anchor = Anchor.center;
  }
}

class MyGame extends BaseGame {
  final double squareSize = 128;

  MyGame() {
    add(Square());
  }
}
1846
likes
0
pub points
98%
popularity

Publisher

verified publisherflame-engine.org

A minimalist Flutter game engine, provides a nice set of somewhat independent modules you can choose from.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

audioplayers, box2d_flame, convert, flare_flutter, flutter, flutter_svg, meta, ordered_set, path_provider, synchronized, tiled

More

Packages that depend on flame