Skip to content

Commit

Permalink
Merge pull request #455 from flame-engine/develop
Browse files Browse the repository at this point in the history
0.26.0 RC
  • Loading branch information
erickzanardo authored Sep 1, 2020
2 parents 5ca9199 + 9312d14 commit 8510f75
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.26.0
- Improving Flame image auto cache
- Fix bug in the Box2DGame's add and addLater method , when the Component extends BodyComponent and mixin HasGameRef or other mixins ,the mixins will not be set correctly

## 0.25.0
- Externalizing Tiled support to its own package `flame_tiled`
- Preventing some crashs that could happen on web when some methods were called
Expand Down
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Put the pub package as your dependency by dropping the following in your `pubspe

```yaml
dependencies:
flame: ^0.25.0
flame: ^0.26.0
```
And start using it!
Expand Down
7 changes: 5 additions & 2 deletions doc/examples/particles/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class MyGame extends BaseGame {
Offset cellSize;
Offset halfCellSize;

@override
bool recordFps() => true;

MyGame({
Size screenSize,
}) {
Expand Down Expand Up @@ -292,7 +295,7 @@ class MyGame extends BaseGame {
Particle imageParticle() {
return ImageParticle(
size: const Size.square(24),
image: Flame.images.loadedFiles['zap.png'],
image: Flame.images.loadedFiles['zap.png'].loadedImage,
);
}

Expand Down Expand Up @@ -522,7 +525,7 @@ class MyGame extends BaseGame {
const rows = 8;
const frames = columns * rows;
const imagePath = 'boom3.png';
final spriteImage = Flame.images.loadedFiles[imagePath];
final spriteImage = Flame.images.loadedFiles[imagePath].loadedImage;
final spritesheet = SpriteSheet(
rows: rows,
columns: columns,
Expand Down
2 changes: 2 additions & 0 deletions lib/box2d/box2d_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Box2DGame extends BaseGame {
@override
void add(Component c) {
if (c is BodyComponent) {
preAdd(c);
box.add(c);
} else {
super.add(c);
Expand All @@ -25,6 +26,7 @@ class Box2DGame extends BaseGame {
@override
void addLater(Component c) {
if (c is BodyComponent) {
preAdd(c);
_addLater.add(c);
} else {
super.addLater(c);
Expand Down
23 changes: 18 additions & 5 deletions lib/images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:convert' show base64;
import 'package:flame/flame.dart';

class Images {
Map<String, Image> loadedFiles = {};
Map<String, ImageAssetLoader> loadedFiles = {};

void clear(String fileName) {
loadedFiles.remove(fileName);
Expand All @@ -22,16 +22,16 @@ class Images {

Future<Image> load(String fileName) async {
if (!loadedFiles.containsKey(fileName)) {
loadedFiles[fileName] = await _fetchToMemory(fileName);
loadedFiles[fileName] = ImageAssetLoader(_fetchToMemory(fileName));
}
return loadedFiles[fileName];
return await loadedFiles[fileName].retreive();
}

Future<Image> fromBase64(String fileName, String base64) async {
if (!loadedFiles.containsKey(fileName)) {
loadedFiles[fileName] = await _fetchFromBase64(base64);
loadedFiles[fileName] = ImageAssetLoader(_fetchFromBase64(base64));
}
return loadedFiles[fileName];
return await loadedFiles[fileName].retreive();
}

Future<Image> _fetchFromBase64(String base64Data) async {
Expand All @@ -52,3 +52,16 @@ class Images {
return completer.future;
}
}

class ImageAssetLoader {
ImageAssetLoader(this.future);

Image loadedImage;
Future<Image> future;

Future<Image> retreive() async {
loadedImage ??= await future;

return loadedImage;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flame
description: A minimalist Flutter game engine, provides a nice set of somewhat independent modules you can choose from.
version: 0.25.0
version: 0.26.0
homepage: https://github.com/flame-engine/flame

dependencies:
Expand Down

0 comments on commit 8510f75

Please sign in to comment.