flame 0.9.5

  • README.md
  • Installing
  • Versions
  • 91

🔥 flame

A minimalist Flutter game engine.

Any help is appreciated! Comment, suggestions, issues, PR's! Give us a star to help!


The goal of this project is to provided a complete set of out-of-the-way solutions for the common problems every game developed in Flutter will share.

Currently it provides you with: a few utilities, images/sprites/sprite sheets, audio, a game loop and a component/object system.

You can use whatever ones you want, as they are all somewhat independent.


Just drop it in your pubspec.yaml:

  flame: ^0.9.5

And start using it!

The complete documentation can be found here.

Bellow is an overview that should suffice to build a simple game, and work your way up from there.

The flame-example game has been updated to use the newer APIs (0.8.2) on a new branch.

There is a very good QuickStart tutorial for version 0.6.1 here. The API has changed a lot, so refer this documentation for updated information. Soon I plan to release an updated tutorial.


The only structure you are required to comply is a assets folder with two sub folders: audio and images.

An example:



The file structure would have to be:

└── assets
    ├── audio
    │   └── explosion.mp3
    └── images
        ├── enemy.png
        └── player.png

Don't forget to add these files to your pubspec.yaml file:

    - assets/audio/explosion.mp3
    - assets/images/player.png
    - assets/images/enemy.png


The modular approach allows you to use any of these modules independently, or together, or as you wish.


To play an audio, just use the Flame.audio.play method:

    import 'package:flame/flame.dart';


You can pre-load your audios in the beginning and avoid delays with the loadAll method:

    // in a async prepare function for your game
    await Flame.audio.loadAll(['explosion.mp3']);

Complete Audio Guide


If you are using the Component module and doing something simple, you probably won't need to use these classes; use SpriteComponent or AnimationComponent instead.

If you want to load an image and render it on the Canvas, you can use the Sprite class:

    import 'package:flame/sprite.dart';

    Sprite sprite = new Sprite('player.png');

    // in your render loop
    sprite.render(canvas, width, height);

Note that the render method will do nothing while the image has not been loaded; you can check for completion using the loaded method.

Complete Images Guide


This class represent a single object on the screen, being a floating rectangle or a rotating sprite.

The base abstract class has the common expected methods update and render to be implemented.

The intermediate inheritance PositionComponent adds x, y, width, height and angle to your Components, as well as some useful methods like distance and angleBetween.

The most commonly used implementation, SpriteComponent, can be created with a Sprite:

    import 'package:flame/components/component.dart';

    Sprite sprite = new Sprite('player.png');

    const size = 128.0;
    var player = new SpriteComponent.fromSprite(size, size, sprite); // width, height, sprite

    // screen coordinates
    player.x = ... // 0 by default
    player.y = ... // 0 by default
    player.angle = ... // 0 by default

    player.render(canvas); // it will render only if the image is loaded and the x, y, width and height parameters are not null

Every Component has a few other methods that you can optionally implement, that are used by the BaseGame class. If you are not using the base game, you can alternatively use these methods on your own game loop.

The resize method is called whenever the screen is resized, and in the beginning once when the component is added via the add method. You need to apply here any changes to the x, y, width and height of your component, or any other changes, due to the screen resizing. You can start these variables here, as the sprite won't be rendered until everything is set.

The destroy method can be implemented to return true and warn the BaseGame that your object is marked for destruction, and it will be remove after the current update loop. It will then no longer be rendered or updated.

The isHUD method can be implemented to return true (default false) to make the BaseGame ignore the camera for this element.

There are also other implementations:

  • The AnimationComponent takes an Animation object and renders a cyclic animated sprite (more details about Animations here)
  • The ParallaxComponent can render a parallax background with several frames
  • The Box2DComponent, that has a physics engine built-in (using the Box2D port for Dart)

Complete Components Guide

Game Loop

The Game Loop module is a simple abstraction over the game loop concept. Basically most games are built upon two methods:

  • The render method takes the canvas ready for drawing the current state of the game.
  • The update method receives the delta time in milliseconds since last update and allows you to move the next state.

The class Game can be subclassed and will provide both these methods for you to implement. In return it will provide you with a widget property that returns the game widget, that can be rendered in your app.

You can either render it directly in your runApp, or you can have a bigger structure, with routing, other screens and menus for your game.

To start, just add your game widget directly to your runApp, like so:

    main() {
        Game game = new MyGameImpl();

Instead of implementing the low level Game class, you should probably use the more full-featured BaseGame class.

The BaseGame implements a Component based Game for you; basically it has a list of Components and repasses the update and render calls appropriately. You can still extend those methods to add custom behavior, and you will get a few other features for free, like the repassing of resize methods (every time the screen is resized the information will be passed to the resize methods of all your components) and also a basic camera feature (that will translate all your non-HUD components in order to center in the camera you specified).

A very simple BaseGame implementation example can be seen below:

    class MyCrate extends SpriteComponent {

        // creates a component that renders the crate.png sprite, with size 16 x 16
        MyCrate() : SpriteComponent.fromSprite(16.0, 16.0, new Sprite('crate.png'));

        void resize(Size size) {
            // we don't need to set the x and y in the constructor, we can set then here
            this.x = (size.width - this.width)/ 2;
            this.y = (size.height - this.height) / 2;

    class MyGame extends BaseGame {
        MyGame() {
            add(new MyCrate()); // this will call resize the first time as well


In order to handle user input, you can use the libraries provided by Flutter for regular apps: Gesture Recognizers.

However, in order to bind them, use the Flame.util.addGestureRecognizer method; in doing so, you'll make sure they are properly unbound when the game widget is not being rendered, and so the rest of your screens will work appropriately.

For example, to add a tap listener ("on click"):

    Flame.util.addGestureRecognizer(new TapGestureRecognizer()
        ..onTapDown = (TapDownDetails evt) => game.handleInput(evt.globalPosition.dx, evt.globalPosition.dy));

Where game is a reference to your game object and handleInput is a method you create to handle the input inside your game.

If your game doesn't have other screens, just call this after your runApp call, in the main method.

Complete Input Guide


Gamepad is partially supported on Android, you easily listen to key up and down events using Flame.gamepad.addListener method, check the link below for the complete guide

Complete Gamepad Guide


  • All the friendly contributors and people who are helping in the community.
  • My own audioplayers lib, which in turn is forked from rxlabz's.
  • The Dart port of Box2D.
  • inu-no-policemen's post on reddit, which helped me a lot with the basics
  • Everyone who answered my beginner's questions on Stack Overflow


  • Add elapsed property to Animation (thanks, @ianliu)
  • Fixed minor typo on documentation


  • Bumps audioplayers version


  • Fixes issue when switching between games where new game would not attach


  • Fixes to work with Dart 2.1


  • Updated audioplayers and box2d to fix bugs


  • Several API changes, using new audioplayers 0.6.x


  • Added more consistent APIs and tests


  • Need to review audioplayers 0.5.x


  • Added better documentation, tutorials and examples
  • Minor tweaks in the API
  • New audioplayers version


  • The Components Overhaul Update: This is major update, even though we are keeping things in alpha (version 0.*)
  • Several major upgrades regarding the component system, new component types, Sprites and SpriteSheets, better image caching, several improvements with structure, a BaseGame, a new Game as a widget, that allows you to embed inside apps and a stop method. More minor changes.


  • Bump required dart version


  • Adding audio suport for iOS (bumping audioplayers version)


  • Adding a text method to Util to more easily render a Paragraph


  • Upgraded AudioPlayers, added method to disable logging
  • Created PositionComponent with some useful methods
  • A few refactorings


  • Added a pre-load method for Audio module


  • Added a loop method for playing audio on loop
  • Added the option to make rectangular SpriteComponents, not just squares


  • First release, basic utilities

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flame: ^0.9.5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flame/flame.dart';
Version Uploaded Documentation Archive
0.9.5 Oct 19, 2018 Go to the documentation of flame 0.9.5 Download flame 0.9.5 archive
0.9.4 Sep 27, 2018 Go to the documentation of flame 0.9.4 Download flame 0.9.4 archive
0.9.3 Sep 27, 2018 Go to the documentation of flame 0.9.3 Download flame 0.9.3 archive
0.9.2 Aug 26, 2018 Go to the documentation of flame 0.9.2 Download flame 0.9.2 archive
0.9.1 Jul 15, 2018 Go to the documentation of flame 0.9.1 Download flame 0.9.1 archive
0.9.0 Jul 11, 2018 Go to the documentation of flame 0.9.0 Download flame 0.9.0 archive
0.8.4 Apr 15, 2018 Go to the documentation of flame 0.8.4 Download flame 0.8.4 archive
0.8.3 Mar 5, 2018 Go to the documentation of flame 0.8.3 Download flame 0.8.3 archive
0.8.2 Mar 5, 2018 Go to the documentation of flame 0.8.2 Download flame 0.8.2 archive
0.8.1 Dec 22, 2017 Go to the documentation of flame 0.8.1 Download flame 0.8.1 archive

All 20 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use flame.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.50.0 <3.0.0
audioplayers ^0.7.7 0.7.8
box2d_flame ^0.4.2 0.4.2
flutter 0.0.0
ordered_set ^1.1.2 1.1.2
path_provider ^0.4.1 0.4.1
synchronized ^1.5.1+1 1.5.3
Transitive dependencies
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
uuid 1.0.3
vector_math 2.0.8
Dev dependencies
test ^1.3.0