Merge pull request #278 from flame-engine/develop

0.19.1 RC
This commit is contained in:
Erick (CptBlackPixel)
2020-04-14 14:03:43 -03:00
committed by GitHub
8 changed files with 75 additions and 23 deletions

View File

@@ -1,3 +1,10 @@
# CHANGELOG
## 1.19.1
- Bump AudioPlayers version to allow for web support
- Adding Game#pauseEngine and Game#resumeEngine methods
- Removing FlameBinding since it isn't used and clashes with newest flutter
## 0.19.0 ## 0.19.0
- Fixing component lifecycle calls on BaseGame#addLater - Fixing component lifecycle calls on BaseGame#addLater
- Fixing Component#onDestroy, which was been called multiple times sometimes - Fixing Component#onDestroy, which was been called multiple times sometimes

View File

View File

@@ -23,7 +23,7 @@ Check out the [awesome flame repository](https://github.com/flame-engine/awesome
```yaml ```yaml
dependencies: dependencies:
flame: ^0.19.0 flame: ^0.19.1
``` ```
And start using it! And start using it!

View File

@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//
// ignore: unused_import
import 'dart:ui';
import 'package:audioplayers/audioplayers_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
void registerPlugins(PluginRegistry registry) {
AudioplayersPlugin.registerWith(registry.registrarFor(AudioplayersPlugin));
registry.registerMessageHandler();
}

View File

@@ -2,13 +2,18 @@ import 'dart:math' as math;
import 'dart:ui'; import 'dart:ui';
import 'package:flame/anchor.dart'; import 'package:flame/anchor.dart';
import 'package:flame/gestures.dart';
import 'package:flame/components/component.dart'; import 'package:flame/components/component.dart';
import 'package:flame/components/mixins/has_game_ref.dart'; import 'package:flame/components/mixins/has_game_ref.dart';
import 'package:flame/game.dart'; import 'package:flame/game.dart';
import 'package:flame/palette.dart'; import 'package:flame/palette.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(MyGame().widget); void main() {
final game = MyGame();
runApp(game.widget);
}
class Palette { class Palette {
static const PaletteEntry white = BasicPalette.white; static const PaletteEntry white = BasicPalette.white;
@@ -47,10 +52,22 @@ class Square extends PositionComponent with HasGameRef<MyGame> {
} }
} }
class MyGame extends BaseGame { class MyGame extends BaseGame with TapDetector {
final double squareSize = 128; final double squareSize = 128;
bool running = true;
MyGame() { MyGame() {
add(Square()); add(Square());
} }
@override
void onTap() {
if (running) {
pauseEngine();
} else {
resumeEngine();
}
running = !running;
}
} }

View File

@@ -54,23 +54,7 @@ class Flame {
_bundle = bundle; _bundle = bundle;
} }
/// TODO verify if this is still needed (I don't think so)
static void initializeWidget() { static void initializeWidget() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
} }
} }
/// This class never needs to be used.
///
/// It only exists here in order for [BindingBase] to setup Flutter services.
/// TODO: this could possibly be private, verify if it'd work.
class FlameBiding extends BindingBase with GestureBinding, ServicesBinding {
static FlameBiding instance;
static FlameBiding ensureInitialized() {
if (FlameBiding.instance == null) {
FlameBiding();
}
return FlameBiding.instance;
}
}

View File

@@ -89,6 +89,18 @@ abstract class Game {
RawKeyboard.instance.removeListener(_handleKeyEvent); RawKeyboard.instance.removeListener(_handleKeyEvent);
} }
} }
/// Flag to tell the game loop if it should start running upon creation
bool runOnCreation = true;
/// Pauses the engine game loop execution
void pauseEngine() => _pauseEngineFn?.call();
/// Resumes the engine game loop execution
void resumeEngine() => _resumeEngineFn?.call();
VoidCallback _pauseEngineFn;
VoidCallback _resumeEngineFn;
} }
class OverlayWidget { class OverlayWidget {
@@ -334,6 +346,7 @@ class GameRenderBox extends RenderBox with WidgetsBindingObserver {
Game game; Game game;
int _frameCallbackId; int _frameCallbackId;
bool _running = false;
Duration previous = Duration.zero; Duration previous = Duration.zero;
@@ -353,7 +366,19 @@ class GameRenderBox extends RenderBox with WidgetsBindingObserver {
super.attach(owner); super.attach(owner);
game.onAttach(); game.onAttach();
_scheduleTick(); game._pauseEngineFn = () {
if (_running) {
previous = Duration.zero;
_unscheduleTick();
}
};
game._resumeEngineFn = () {
if (!_running) _scheduleTick();
};
if (game.runOnCreation) _scheduleTick();
_bindLifecycleListener(); _bindLifecycleListener();
} }
@@ -366,11 +391,15 @@ class GameRenderBox extends RenderBox with WidgetsBindingObserver {
} }
void _scheduleTick() { void _scheduleTick() {
_running = true;
_frameCallbackId = SchedulerBinding.instance.scheduleFrameCallback(_tick); _frameCallbackId = SchedulerBinding.instance.scheduleFrameCallback(_tick);
} }
void _unscheduleTick() { void _unscheduleTick() {
SchedulerBinding.instance.cancelFrameCallbackWithId(_frameCallbackId); _running = false;
if (_frameCallbackId != null) {
SchedulerBinding.instance.cancelFrameCallbackWithId(_frameCallbackId);
}
} }
void _tick(Duration timestamp) { void _tick(Duration timestamp) {

View File

@@ -1,12 +1,12 @@
name: flame name: flame
description: A minimalist Flutter game engine, provides a nice set of somewhat independent modules you can choose from. description: A minimalist Flutter game engine, provides a nice set of somewhat independent modules you can choose from.
version: 0.19.0 version: 0.19.1
homepage: https://github.com/flame-engine/flame homepage: https://github.com/flame-engine/flame
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
audioplayers: ^0.15.0 audioplayers: ^0.15.1
ordered_set: ^2.0.0 ordered_set: ^2.0.0
path_provider: ^1.6.0 path_provider: ^1.6.0
box2d_flame: ^0.4.5 box2d_flame: ^0.4.5