Files
flame/examples/lib/stories/system/overlays_example.dart
Lukas Klingsbo 8b132d7c0b Unify examples structure (#1118)
* Animations, CameraAndViewport, CollisionDetection and Components unified

* Added descriptions to effects

* Rename input games

* Unify input stories

* Add info to parallax section

* Added descriptions to the rendering examples

* Add descriptions to the sprites directory

* Fix utils and rendering section

* Add descriptions to the widgets section

* Delete directory that rebase brought back

* Unify game names

* Added some styleguide docs for examples

* Fix analyze issues

* All files should have _example as suffix

* Made the FollowComponentExample a bit easier to understand

* Change priority of ember
2021-11-19 14:28:04 +01:00

71 lines
1.7 KiB
Dart

import 'package:dashbook/dashbook.dart';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flutter/material.dart';
class OverlaysExample extends FlameGame with TapDetector {
static const String description = '''
In this example we show how the overlays system can be used.\n\n
If you tap the canvas the game will start and if you tap it again it will
pause.
''';
@override
Future<void> onLoad() async {
await super.onLoad();
final animation = await loadSpriteAnimation(
'animations/chopper.png',
SpriteAnimationData.sequenced(
amount: 4,
textureSize: Vector2.all(48),
stepTime: 0.15,
),
);
add(
SpriteAnimationComponent(
animation: animation,
)
..position.y = size.y / 2
..position.x = 100
..anchor = Anchor.center
..size = Vector2.all(100),
);
}
@override
void onTap() {
if (overlays.isActive('PauseMenu')) {
overlays.remove('PauseMenu');
resumeEngine();
} else {
overlays.add('PauseMenu');
pauseEngine();
}
}
}
Widget _pauseMenuBuilder(BuildContext buildContext, OverlaysExample game) {
return Center(
child: Container(
width: 100,
height: 100,
color: Colors.orange,
child: const Center(
child: Text('Paused'),
),
),
);
}
Widget overlayBuilder(DashbookContext ctx) {
return GameWidget<OverlaysExample>(
game: OverlaysExample()..paused = true,
overlayBuilderMap: const {
'PauseMenu': _pauseMenuBuilder,
},
initialActiveOverlays: const ['PauseMenu'],
);
}