gnarhard / flame_texturepacker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flame_texturepacker

A flame plugin to import sprite sheets generated by Gdx Texture Packer and Code and Web Texture Packer

Install from Dart Pub

Include the following to your pubspec.yaml file:

dependencies:
  flame_texturepacker: any

Usage

Drop generated atlas file and sprite sheet images into the assets/ and link the files in your pubspec.yaml file:

 assets:
    - assets/spriteSheet.atlas
    - assets/spriteSheet.png

Import the plugin like this:

import 'package:flame_texturepacker/flame_texturepacker.dart';

Load the TextureAtlas passing the path of the sprite sheet atlas file:

final atlas = await fromAtlas('FlameAtlasMap.atlas');

Get a list of sprites ordered by their index, you can use the list to generate an animation:

final spriteList = atlas.findSpritesByName('robot_walk');

final animation = SpriteAnimation.spriteList(
 spriteList,
 stepTime: 0.1,
 loop: true,
);

Get individual sprites by name:

final jumpSprite = atlas.findSpriteByName('robot_jump')!;
final fallSprite = atlas.findSpriteByName('robot_fall')!;
final idleSprite = atlas.findSpriteByName('robot_idle')!;

Full working example can be found in example folder.

Note: Sprites used in this example can be found OpenGameArt here.

About

License:MIT License


Languages

Language:Dart 75.4%Language:Ruby 10.5%Language:HTML 7.5%Language:Swift 5.9%Language:Kotlin 0.5%Language:Objective-C 0.2%