flim 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

flim ✨ #

Minimal data-driven sprite render lib for Flutter

Features #

  • Sprites and sprite animations with transforms
  • Buffered sprite rendering using Canvas.drawAtlas (fast!)
  • Data-driven: load sprites and animations as json
  • Abstractions for game, render-loop, widgets and more
  • Generic asset cache used for images, json and more
  • Minimal and loosely coupled Flutter package

Usage #

Add flim to your pubspec.yaml:

dependencies:
  flim:

See USAGE.md and example to learn.

Use dartdoc or scripts/docs.sh to generate docs.

Notes #

I'd like to keep flim minimal, so i won't be adding lots of game features.

Code is expected to break.

Code and doc improvements are welcome.

Inspired by Flame

CHANGELOG #

[0.3.1] #

  • format code
  • minor json load improvement
  • update README

[0.3.0] #

  • refactor and simplify Sprite (and json format) by removing ImageRect
  • rename Transform2 -> Transform2D
  • more lambdas

[0.2.4] #

  • update README

[0.2.0] #

  • rename sprite load to loadImage
  • update docs

[0.1.1] #

  • initial release!
  • sprites and sprite animations
  • buffered sprite rendering using Canvas.drawAtlas
  • load sprites from json assets
  • game, render box, render-loop, widgets+
  • generic asset cache for images, json, strings etc
  • examples using sprites, animations, keyboard+

example/lib/main.dart

import 'package:example/my_benchmark_game.dart';
import 'package:flutter/material.dart';

import 'package:flim/flim.dart';

import 'my_game_widget.dart';
import 'my_playground_game.dart';
import 'my_simple_game.dart';
import 'my_keyboard_game.dart';

void main() async {
  ImageAssets.instance.basePath = "assets/images/";
  JsonAssets.instance.basePath = "assets/json/";
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
        appBarTheme: AppBarTheme(
          elevation: 0,
          color: Colors.black26,
        ),
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flim example'),
      ),
      body: buildGameAndWidgets(),
    );
  }

  Widget buildBenchmarkGame() {
    return FutureBuilder(
      future: MyBenchmarkGame(MediaQuery.of(context).size).initialize(),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return GameWidget(snapshot.data);
        } else {
          return Container();
        }
      },
    );
  }

  Widget buildKeyboardGame() {
    return Stack(
      children: [
        FutureBuilder(
          future: MyKeyboardGame(MediaQuery.of(context).size).initialize(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return MyGameWidget(snapshot.data);
            } else {
              return Container();
            }
          },
        ),
        Padding(
          padding: EdgeInsets.all(32),
          child: Align(
            alignment: Alignment.bottomCenter,
            child: Text(
              'press \'hjkl\' to move and \'f\' to fire',
              style: TextStyle(
                fontSize: 17,
              ),
            ),
          ),
        ),
      ],
    );
  }

  Widget buildAnimationWithTwoImage() {
    return FutureBuilder(
      future: AnimatedSprite.loadJson('animation_two_images.json'),
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return GameWidget(AnimatedSpriteGame(snapshot.data));
        } else {
          return Container();
        }
      },
    );
  }

  Widget buildSimpleGameAndWidgets() {
    return Row(
      children: [
        FutureBuilder(
          future: Sprite(
            imagePath: 'boom3.PNG',
            rect: IntRect(512, 512, 128, 128),
            color: Colors.yellowAccent,
            transform: Transform2D(
              anchor: Offset(64.0, 64.0),
            ),
          ).loadImage(),
          builder: (context, snapshot) {
            return Container(
              width: 300,
              height: 200,
              color: Colors.blueAccent,
              child: Center(
                child: snapshot.hasData
                    ? SpriteWidget(snapshot.data)
                    : Container(),
              ),
            );
          },
        ),
        FutureBuilder(
          future: MySimpleGame().initialize(),
          builder: (context, snapshot) {
            return Container(
              width: 200,
              height: 200,
              color: Colors.redAccent,
              child: snapshot.hasData
                  ? GameWidget(
                      snapshot.data,
                      size: Size(200, 200),
                    )
                  : Container(),
            );
          },
        ),
      ],
    );
  }

  Widget buildGameAndWidgets() {
    return Stack(
      children: [
        FutureBuilder(
          future: MyPlaygroundGame().initialize(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return GameWidget(snapshot.data);
            } else {
              return Container();
            }
          },
        ),
        FutureBuilder(
          future: Sprite(
            imagePath: 'AngelBrown.PNG',
            transform: Transform2D(
              translate: Offset(100, 200),
              scale: 2.0,
              rotation: 3.14 / 4.0,
            ),
          ).loadImage(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return SpriteWidget(snapshot.data);
            } else {
              return Container();
            }
          },
        ),
        FutureBuilder(
          future: AnimatedSprite.fromUniformSpriteSheet(
            imagePath: 'boom3.png',
            spriteSize: IntSize(128, 128),
            atlasBounds: IntRect(0, 0, 8, 8),
            frameDuration: 0.03,
            color: Colors.transparent,
            transform: Transform2D(
              translate: Offset(0.0, 128 * 2.0),
            ),
          ).loadImages(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return GameWidget(AnimatedSpriteGame(snapshot.data));
            } else {
              return Container();
            }
          },
        ),
      ],
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flim: ^0.3.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flim/flim.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • flim that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test