mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-18 05:38:39 +08:00
@@ -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
|
||||||
|
|||||||
@@ -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!
|
||||||
|
|||||||
15
example/lib/generated_plugin_registrant.dart
Normal file
15
example/lib/generated_plugin_registrant.dart
Normal 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();
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user