flame_texturepacker 4.0.0 copy "flame_texturepacker: ^4.0.0" to clipboard
flame_texturepacker: ^4.0.0 copied to clipboard

A simple plugin for the Flame Engine to import spritesheets generated by the TexturePacker tool.

example/lib/main.dart

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_texturepacker/flame_texturepacker.dart';
import 'package:flutter/material.dart';

void main() {
  final myGame = MyGame();
  runApp(
    GameWidget(
      game: myGame,
    ),
  );
}

class MyGame extends FlameGame {
  @override
  Future<void> onLoad() async {
    super.onLoad();

    // Load the atlasMap.
    final atlas = await atlasFromAssets('atlas_map.atlas');

    // Get a list of sprites ordered by their index
    final walkingSprites = atlas.findSpritesByName('robot_walk');

    // Create animation with the list of sprites
    final walkingAnimation = SpriteAnimation.spriteList(
      walkingSprites,
      stepTime: 0.1,
    );

    // Get individual sprites by name
    final jumpSprite = atlas.findSpriteByName('robot_jump')!;
    final fallSprite = atlas.findSpriteByName('robot_fall')!;
    final idleSprite = atlas.findSpriteByName('robot_idle')!;

    // Get the list of all sprites in the sprite sheet
    final allSprites = atlas.sprites; // ignore: unused_local_variable

    add(
      SpriteComponent(
        sprite: jumpSprite,
        position: Vector2(200, 100),
        size: Vector2(72, 96),
      ),
    );

    add(
      SpriteComponent(
        sprite: fallSprite,
        position: Vector2(300, 100),
        size: Vector2(72, 96),
      ),
    );

    add(
      SpriteComponent(
        sprite: idleSprite,
        position: Vector2(400, 100),
        size: Vector2(72, 96),
      ),
    );

    add(
      SpriteAnimationComponent(
        animation: walkingAnimation,
        position: Vector2(300, 200),
        size: Vector2(72, 96),
      ),
    );
  }
}
11
likes
140
pub points
78%
popularity

Publisher

verified publisherflame-engine.org

A simple plugin for the Flame Engine to import spritesheets generated by the TexturePacker tool.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

MIT (LICENSE)

Dependencies

collection, flame, flutter

More

Packages that depend on flame_texturepacker