Git Product home page Git Product logo

flame_tiled_utils's Introduction

Features

  1. Merge a layer of tiled map into component to render as single image. It allows to improve performance on large maps
  2. Map each tile to dart class or process function using "Type" parameter as key
  3. Extract animation from tiles, allows to render maps with animated tiles.
  4. Merge animated tiles of same type into one big SpriteAnimation component. It allows to improve performance for large animated fields.

Usage

Merging statical layers

Instead of rendering tiled map as usual:

final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
add(mapComponent);

convert it into special component:

final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
final imageCompiler = ImageBatchCompiler();
final ground = await imageCompiler.compileMapLayer(tileMap: mapComponent.tileMap, layerNames: ['ground']);
ground.priority = RenderPriority.ground.priority;
add(ground);

The layerNames variable allows you to specify layers to convert. It is useful when different map layers should have different priorities.

Map tiles to components

If you need to process each tile individually - use TileProcessor:

final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
TileProcessor.processTileType(
  tileMap: mapComponent.tileMap,
  processorByType: <String, TileProcessorFunc>{
    'water': ((tile, position, size) {
      /// Create here a new object, save tile data or process it
      /// a way your game logics need
    }),
  },
  layersToLoad: [
  'water',
]);

The first parameter of TileProcessorFunc is instance of TileProcessor class.

Extracting tile data

Use instance of TileProcessor inside of TileProcessorFunc to access all necessary data:

  • tile.getSprite() to get Sprite object of the tile
  • tile.getSpriteAnimation() to get SpriteAnimation object of the tile. It brings tiled support of animated map - missing but strongly required feature
  • tile.getCollisionRect() allows to load RectangleHitbox, if collision rect was specified in Tiled editor. The library only supports rectangular shapes.

Rendering large fields of animated tiles

It is cheaper to merge multiple small animated tiles into big one, then render each tile with same animation. This could be achieved by combining TileProcessor.processTileType and AnimationBatchCompiler:

final mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
final animationCompiler = AnimationBatchCompiler();
TileProcessor.processTileType(
        tileMap: tiledComponent.tileMap,
        processorByType: <String, TileProcessorFunc>{
          'water': ((tile, position, size) {
            animationCompiler.addTile(position, tile);
          }),
        },
        layersToLoad: [
          'water',
        ]);
final animatedWater = await animationCompiler.compile();
animatedWater.priority = RenderPriority.water.priority;
add(animatedWater);

flame_tiled_utils's People

Contributors

asgalex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.