Size and screen size

Flame game development framework is based Flutter, Flutter when using logical pixel drawn on the screen, so when adjusting the game objects in the Flame size we are using logical pixels.

In fact, there is a adjustment (resize) method on the game (Game) abstract class, this method accepts size (Size) class parameters, you can use this parameter to determine the screen size of the device.

First, the box-game.dart file, add an instance variable screenSize a BoxGame class, this variable is used to keep the size of the screen only when a change in the size of the screen will be updated, it is also the Flame draw objects on the screen basis. Size is variable screenSize type, consistent with the parameters passed to the adjustment (a resize) method.

ScreenSize initial class variable is null, the rendering process can be used to determine whether the screen size is known. Next, we write a method with the same name covering adjustment (resize) method.

class BoxGame extends Game {
Size screenSize;

...

a resize void (Size size) {
screenSize = size;
super.resize (size);
}
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
Up to this point, our box-game.dart which should have the following code.

import 'dart:ui';

import 'package:flame/game.dart';

class BoxGame extends Game {
Size screenSize;

the render void (the Canvas Canvas) {
// the TODO: implement rendering
} (http://www.amjmh.com/v/)

Update void (Double T) {
// the TODO: Update achieve
}

void resize(Size size) {
screenSize = size;
super.resize(size);
}
}

Guess you like

Origin www.cnblogs.com/ly570/p/11488508.html