Files
flame/packages/flame_tiled/test/test_image_utils.dart
John McDole bc2db2b17a TiledAtlas (#1982)
Allocate an atlas per map to keep sprite paint orders correct.  If you
already use one atlas permap, this will have no benifit. Multiple
tileset images will see both a performance gain from single batch
renders, and correct painting on staggered maps.

Fix animations with offets
- Remove TiledLayer._loadImages - no longer used.
- Animations that are in other layers need also translate by offset

Cheap 2D rect bin packing
- Sort: images from large->small
- Keep searching for smallest rect, but input rects should be big->small

Parallel load atlas images

Moved some testing classes around for better code sharing

Fixed tests for external tsx loading. It is dangerous to override global
static values...

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
2022-10-06 05:53:06 +00:00

24 lines
757 B
Dart

import 'dart:typed_data';
import 'dart:ui';
import 'package:flame/extensions.dart';
import 'package:flame_tiled/flame_tiled.dart';
Future<Uint8List> renderMapToPng(
TiledComponent component,
) async {
final canvasRecorder = PictureRecorder();
final canvas = Canvas(canvasRecorder);
component.tileMap.render(canvas);
final picture = canvasRecorder.endRecording();
final size = component.size;
// Map size is now 320 wide, but it has 1 extra tile of height because
// its actually double-height tiles.
final image = await picture.toImageSafe(size.x.toInt(), size.y.toInt());
return imageToPng(image);
}
Future<Uint8List> imageToPng(Image image) async =>
(await image.toByteData(format: ImageByteFormat.png))!.buffer.asUint8List();