mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
* Adding game to overlaybuilder and visible overlays * Fixing things * Format * Adding Renan's suggestions * Removing wrongly commited integration test files * Fixing active overlay when it is null * Update CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Adding some more changes from suggestions * Removing unnecessary elvis operator Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
71 lines
1.5 KiB
Dart
71 lines
1.5 KiB
Dart
import 'package:flame/game.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import './example_game.dart';
|
|
|
|
void main() {
|
|
runApp(MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: MyHomePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
MyHomePage({Key key}) : super(key: key);
|
|
|
|
@override
|
|
_MyHomePageState createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
ExampleGame _myGame;
|
|
|
|
Widget pauseMenuBuilder(BuildContext buildContext, ExampleGame game) {
|
|
return Center(
|
|
child: Container(
|
|
width: 100,
|
|
height: 100,
|
|
color: const Color(0xFFFF0000),
|
|
child: const Center(
|
|
child: const Text('Paused'),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Testing addingOverlay'),
|
|
),
|
|
body: _myGame == null
|
|
? const Text('Wait')
|
|
: GameWidget<ExampleGame>(
|
|
game: _myGame,
|
|
overlayBuilderMap: {
|
|
"PauseMenu": pauseMenuBuilder,
|
|
},
|
|
initialActiveOverlays: const ['PauseMenu'],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => newGame(),
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
void newGame() {
|
|
setState(() {
|
|
_myGame = ExampleGame();
|
|
print('New game created');
|
|
});
|
|
}
|
|
}
|