Skip to content

Commit 5ca9199

Browse files
authored
Merge pull request #444 from flame-engine/develop
0.25.0 RC
2 parents ac78238 + 9f48a98 commit 5ca9199

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+242
-7217
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 0.25.0
4+
- Externalizing Tiled support to its own package `flame_tiled`
5+
- Preventing some crashs that could happen on web when some methods were called
6+
- Add mustCallSuper to BaseGame `update` and `render` methods
7+
- Moved FPS code from BaseGame to a mixin, BaseGame uses the new mixin.
8+
- Deprecate flare API in favor of the package `flame_flare`
9+
310
## 0.24.0
411
- Outsourcing SVG support to an external package
512
- Adding MemoryCache class

doc/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Put the pub package as your dependency by dropping the following in your `pubspe
1818

1919
```yaml
2020
dependencies:
21-
flame: ^0.24.0
21+
flame: ^0.25.0
2222
```
2323
2424
And start using it!

doc/box2d.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Box2D
22

3-
Although Flame does not implements Box2d itself, it bundles a forked port of the Java Box2d to Dart by Google.
3+
Although Flame does not implement Box2d itself, it bundles a forked port of the Java Box2d to Dart by Google.
44

55
The source of the bundled box2d on Flame can be found [here](https://github.com/flame-engine/box2d.dart).
66

doc/components.md

+50-14
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,56 @@ This component uses an instance of `Svg` class to represent a Component that has
7878
android.y = 100;
7979
```
8080

81-
## FlareAnimation Component
81+
## FlareActor Component
8282

83-
This component wraps an instance of the [FlareAnimation](/doc/images.md#FlareAnimation), it receives the filename of the Flare animation file, which animation from that file you want to use, and the `width` and `height` of the rendered animation.
83+
*Note*: The previous implementation of a Flare integration API using `FlareAnimation` and `FlareComponent` has been deprecated.
8484

85-
```dart
86-
final fileName = "assets/Bob_Minion.flr";
87-
final animation = "Wave";
88-
final width = 306;
89-
final height = 228;
85+
To use Flare within Flame, use the [`flame_flare`](https://github.com/flame-engine/flame_flare) package.
86+
87+
This is the interface to use a [flare animation](https://pub.dev/packages/flare_flutter) within flame.
88+
`FlareActorComponent` has almost the same API as of flare's FlareActor widget. It receives the animation filename (that are loaded by default with `Flame.bundle`),
89+
it also can receive a FlareController that can play multiple animations and control nodes.
9090

91-
FlareComponent flareAnimation = FlareComponent(fileName, animation, width, height);
91+
```dart
92+
import 'package:flame_flare/flame_flare.dart';
93+
94+
// your implementation of FlareController
95+
class WashingtonController extends FlareControls {
96+
97+
ActorNode rightHandNode;
98+
99+
void initialize(FlutterActorArtboard artboard) {
100+
super.initialize(artboard);
101+
102+
// get flare node
103+
rightHand = artboard.getNode('right_hand');
104+
}
105+
}
106+
107+
final fileName = 'assets/george_washington.flr';
108+
final width = 1776;
109+
final height = 1804;
110+
final controller = WashingtonController(); //instantiate controller
111+
112+
FlareActorComponent flareAnimation = FlareActorComponent(
113+
fileName,
114+
controller: controller,
115+
width: 306,
116+
height: 228,
117+
);
118+
92119
flareAnimation.x = 50;
93120
flareAnimation.y = 240;
94121
add(flareAnimation);
122+
123+
// to play an animation
124+
controller.play('rise_up');
125+
126+
// you can add another animation to play at the same time
127+
controller.play('close_door_way_out');
128+
129+
// also, get a flare node and modify it
130+
controller.rightHandNode.rotation = math.pi;
95131
```
96132

97133
You can also change the current playing animation using the `updateAnimation` method.
@@ -139,9 +175,9 @@ Create it like this:
139175

140176
```dart
141177
final images = [
142-
ParallaxImage("mountains.jpg"),
143-
ParallaxImage("forest.jpg"),
144-
ParallaxImage("city.jpg"),
178+
ParallaxImage('mountains.jpg'),
179+
ParallaxImage('forest.jpg'),
180+
ParallaxImage('city.jpg'),
145181
];
146182
this.bg = ParallaxComponent(images);
147183
```
@@ -163,9 +199,9 @@ By default the images are aligned to the bottom left, repeated along the X-axis
163199
Advanced example:
164200
```dart
165201
final images = [
166-
ParallaxImage("stars.jpg", repeat: ImageRepeat.repeat, alignment: Alignment.center, fill: LayerFill.width),
167-
ParallaxImage("planets.jpg", repeat: ImageRepeat.repeatY, alignment: Alignment.bottomLeft, fill: LayerFill.none),
168-
ParallaxImage("dust.jpg", repeat: ImageRepeat.repeatX, alignment: Alignment.topRight, fill: LayerFill.height),
202+
ParallaxImage('stars.jpg', repeat: ImageRepeat.repeat, alignment: Alignment.center, fill: LayerFill.width),
203+
ParallaxImage('planets.jpg', repeat: ImageRepeat.repeatY, alignment: Alignment.bottomLeft, fill: LayerFill.none),
204+
ParallaxImage('dust.jpg', repeat: ImageRepeat.repeatX, alignment: Alignment.topRight, fill: LayerFill.height),
169205
];
170206
this.bg = ParallaxComponent(images, baseSpeed: Offset(50, 0), layerDelta: Offset(20, 0));
171207
```

doc/debug.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
## Debug features
1+
# Debug features
2+
3+
## FPS counter
4+
5+
Flame provides the `FPSCounter` mixin for recording the fps, this mixin can be applied on any class that extends from `Game`. When applied you have to implemented the `recordFps` method and it should return `true` if you want to access the current fps by using the `fps` method`.
6+
7+
```dart
8+
class MyGame extends Game with FPS {
9+
@override
10+
bool recordFps() => true;
11+
}
12+
```
13+
14+
## BaseGame features
215

316
Flame provides some features for debugging, these features are enabled when the method `debugMode` from the `BaseGame` class is overridden, and returning `true`. When it's enabled all `PositionComponent`s will be wrapped into a rectangle, and have its position rendered on the screen, so you can visually verify the component boundaries and position.
417

5-
In addition to the debugMode, you can also ask BaseGame to record the fps, that is enabled by overriding the `recordFps` method to return `true`, by doing so, you can access the current fps by using the method `fps`.
18+
In addition to the debugMode, you can also ask `BaseGame` to record the fps(the `BaseGame` used the [FPSCounter](fps-counter) mixin). To enable it you have to override the `recordFps` method to return `true`, by doing so, you can access the current fps by using the method `fps`.
619

7-
To see a working example of the debugging features, [check this example](/doc/examples/debug).
20+
To see a working example of the debugging features of the `BaseGame`, [check this example](/doc/examples/debug).

doc/examples/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ web/
22
ios/
33
android/
44
test/
5+
macos/
56

67
generated_plugin_registrant.dart

doc/examples/animations/lib/main.dart

+27-14
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ import 'package:flutter/material.dart';
88

99
void main() async {
1010
WidgetsFlutterBinding.ensureInitialized();
11+
await Flame.images.loadAll(['creature.png', 'chopper.png']);
12+
1113
final Size size = await Flame.util.initialDimensions();
1214
final game = MyGame(size);
1315
runApp(game.widget);
1416
}
1517

1618
class MyGame extends BaseGame with TapDetector {
17-
final animation = flame_animation.Animation.sequenced('chopper.png', 4,
18-
textureWidth: 48, textureHeight: 48, stepTime: 0.15, loop: true);
19+
final animation = flame_animation.Animation.sequenced(
20+
'chopper.png',
21+
4,
22+
textureWidth: 48,
23+
textureHeight: 48,
24+
stepTime: 0.15,
25+
loop: true,
26+
);
1927

2028
void addAnimation(double x, double y) {
2129
const textureWidth = 291.0;
2230
const textureHeight = 178.0;
2331
final animationComponent = AnimationComponent.sequenced(
24-
291, 178, 'creature.png', 18,
25-
amountPerRow: 10,
26-
textureWidth: textureWidth,
27-
textureHeight: textureHeight,
28-
stepTime: 0.15,
29-
loop: true,
30-
destroyOnFinish: true);
32+
291,
33+
178,
34+
'creature.png',
35+
18,
36+
amountPerRow: 10,
37+
textureWidth: textureWidth,
38+
textureHeight: textureHeight,
39+
stepTime: 0.15,
40+
loop: false,
41+
destroyOnFinish: true,
42+
);
3143
animationComponent.x = x - textureWidth / 2;
3244
animationComponent.y = y - textureHeight / 2;
3345

@@ -42,14 +54,15 @@ class MyGame extends BaseGame with TapDetector {
4254
MyGame(Size screenSize) {
4355
size = screenSize;
4456

45-
final animationComponent = AnimationComponent(100, 100, animation);
46-
animationComponent.x = size.width / 2 - 100;
47-
animationComponent.y = 100;
57+
const s = 100.0;
58+
final animationComponent = AnimationComponent(s, s, animation);
59+
animationComponent.x = size.width / 2 - s;
60+
animationComponent.y = s;
4861

4962
final reversedAnimationComponent =
50-
AnimationComponent(100, 100, animation.reversed());
63+
AnimationComponent(s, s, animation.reversed());
5164
reversedAnimationComponent.x = size.width / 2;
52-
reversedAnimationComponent.y = 100;
65+
reversedAnimationComponent.y = s;
5366

5467
add(animationComponent);
5568
add(reversedAnimationComponent);

doc/examples/aseprite/lib/main.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class MyGame extends BaseGame {
1818

1919
void _start() async {
2020
final animation = await flame_animation.Animation.fromAsepriteData(
21-
'chopper.png', 'chopper.json');
21+
'chopper.png',
22+
'chopper.json',
23+
);
2224
final animationComponent = AnimationComponent(200, 200, animation);
2325

2426
animationComponent.x = (size.width / 2) - 100;

doc/examples/audiopool/lib/main.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ TextConfig regular = TextConfig(color: BasicPalette.white.color);
2121
AudioPool pool = AudioPool('laser.mp3');
2222

2323
class MyGame extends BaseGame with TapDetector {
24+
static final black = BasicPalette.black.paint;
25+
2426
MyGame(Size screenSize) {
2527
size = screenSize;
2628
}
2729

2830
@override
2931
void render(Canvas canvas) {
30-
canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height),
31-
BasicPalette.black.paint);
32-
regular.render(canvas, 'hit me!', Position.fromSize(size).div(2),
33-
anchor: Anchor.center);
32+
canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), black);
33+
final p = Position.fromSize(size).div(2);
34+
regular.render(canvas, 'hit me!', p, anchor: Anchor.center);
3435
super.render(canvas);
3536
}
3637

doc/examples/cleanup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ rm -rf */ios
66
rm -rf */web
77
rm -rf */macos
88
rm -rf */test
9+
rm -rf */.dart_tool

doc/examples/flare/.gitignore

-72
This file was deleted.

doc/examples/flare/.metadata

-10
This file was deleted.

doc/examples/flare/README.md

-7
This file was deleted.

0 commit comments

Comments
 (0)