Fixing release mode on examples that needed screenSize

This commit is contained in:
Erick Zanardo
2019-06-29 13:20:08 -03:00
parent ffe41c873b
commit 23fd8c8bc0
4 changed files with 38 additions and 34 deletions

View File

@ -5,9 +5,11 @@ import 'package:flame/animation.dart' as flame_animation;
import 'package:flame/components/animation_component.dart';
import 'package:flutter/material.dart';
void main() {
final game = MyGame();
void main() async {
final Size size = await Flame.util.initialDimensions();
final game = MyGame(size);
runApp(game.widget);
Flame.util.addGestureRecognizer(TapGestureRecognizer()
..onTapDown = (TapDownDetails evt) {
game.addAnimation();
@ -18,9 +20,7 @@ class MyGame extends BaseGame {
final animation = flame_animation.Animation.sequenced('chopper.png', 4,
textureWidth: 48, textureHeight: 48, stepTime: 0.15);
MyGame() {
_start();
}
Size screenSize;
void addAnimation() {
final animationComponent = AnimationComponent(100, 100, animation, destroyOnFinish: true);
@ -30,16 +30,14 @@ class MyGame extends BaseGame {
add(animationComponent);
}
void _start() async {
final Size size = await Flame.util.initialDimensions();
MyGame(this.screenSize) {
final animationComponent = AnimationComponent(100, 100, animation);
animationComponent.x = size.width / 2 - 100;
animationComponent.x = screenSize.width / 2 - 100;
animationComponent.y = 100;
final reversedAnimationComponent =
AnimationComponent(100, 100, animation.reversed());
reversedAnimationComponent.x = size.width / 2;
reversedAnimationComponent.x = screenSize.width / 2;
reversedAnimationComponent.y = 100;
add(animationComponent);