Use Flame plug-in

Adding flame plug-in pubspec.yaml, and get command to download the plugin flutter packages, or use the Visual Studio Code save the file will automatically download the plug.

dependencies:
flutter:
sdk: flutter

cupertino_icons: ^0.1.2

Flame: ^ 0.13.0
1
2
3
4
5
6
7
Flame plug-in has provided a complete game development framework, so we just need to concentrate on writing the actual update and rendering process. First, the application needs to be converted to the game mode, do two operations: full-screen and the longitudinal direction. And people feel that Pakistan proper, Flame plug-in has a good package these useful features, we only need to write the code to call it.

Let's quote at the top Add main.dart below.

Import 'Package: Flame / util.dart';
Import 'Package: Flutter / services.dart';
. 1
2
and then create an instance of the class Util Flame main.dart inside the main function, the call to full screen examples (the fullScreen) and arrangement direction (the setOrientation) function, keeping in mind that, because these functions return type is the future (future), so to wait in front of these added functions (await).

Future (Future), asynchronous (async) and wait (await) is a special coding method, it allows code that takes a long time to complete the deal done on a different thread, but will not block the main thread.

To be able to wait (await) (Future) process is completed in the future, the relevant code must be within an asynchronous (async) function, so we have to modify the main functions, making it an asynchronous function.

main void () {the async
Util flameUtil = Util ();
the await flameUtil.fullScreen (http://www.amjmh.com/v/BIBRGZ_558768/);
the await flameUtil.setOrientation (DeviceOrientation.portraitUp);
. 1
2
. 3
. 4
here So far, our main.dart which should have the following code.

import 'package:flutter/material.dart';

import 'package:flame/util.dart';
import 'package:flutter/services.dart';

void main() async {
Util flameUtil = Util();
await flameUtil.fullScreen();
await flameUtil.setOrientation(DeviceOrientation.portraitUp);
}

Guess you like

Origin www.cnblogs.com/hyhy904/p/11488487.html