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

View File

@ -4,22 +4,25 @@ import 'package:flame/animation.dart' as flame_animation;
import 'package:flame/components/animation_component.dart'; import 'package:flame/components/animation_component.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(MyGame().widget); void main() async{
final Size size = await Flame.util.initialDimensions();
runApp(MyGame(size).widget);
}
class MyGame extends BaseGame { class MyGame extends BaseGame {
MyGame() { Size screenSize;
MyGame(this.screenSize) {
_start(); _start();
} }
void _start() async { void _start() async {
final Size size = await Flame.util.initialDimensions();
final animation = await flame_animation.Animation.fromAsepriteData( final animation = await flame_animation.Animation.fromAsepriteData(
'chopper.png', 'chopper.json'); 'chopper.png', 'chopper.json');
final animationComponent = AnimationComponent(200, 200, animation); final animationComponent = AnimationComponent(200, 200, animation);
animationComponent.x = (size.width / 2) - 100; animationComponent.x = (screenSize.width / 2) - 100;
animationComponent.y = (size.height / 2) - 100; animationComponent.y = (screenSize.height / 2) - 100;
add(animationComponent); add(animationComponent);
} }

View File

@ -3,7 +3,10 @@ import 'package:flame/game.dart';
import 'package:flame/components/component.dart'; import 'package:flame/components/component.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(MyGame().widget); void main() async {
final Size size = await Flame.util.initialDimensions();
runApp(MyGame(size).widget);
}
class Ball extends PositionComponent { class Ball extends PositionComponent {
final Size gameSize; final Size gameSize;
@ -37,19 +40,20 @@ class Ball extends PositionComponent {
} }
class MyGame extends BaseGame { class MyGame extends BaseGame {
MyGame() { Size screenSize;
MyGame(this.screenSize) {
_start(); _start();
} }
void _start() async { void _start() async {
final Size size = await Flame.util.initialDimensions();
Flame.audio.disableLog(); Flame.audio.disableLog();
Flame.audio.load('boin.mp3'); Flame.audio.load('boin.mp3');
Flame.audio.loop('music.mp3', volume: 0.4); Flame.audio.loop('music.mp3', volume: 0.4);
add(Ball(size) add(Ball(this.screenSize)
..y = (size.height / 2) - 50 ..y = (this.screenSize.height / 2) - 50
..width = 100 ..width = 100
..height = 100); ..height = 100);
} }

View File

@ -9,7 +9,10 @@ import 'package:flame/palette.dart';
import 'package:flame/text_config.dart'; import 'package:flame/text_config.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() => runApp(MyGame().widget); void main() async {
final Size size = await Flame.util.initialDimensions();
runApp(MyGame(size).widget);
}
TextConfig regular = TextConfig(color: BasicPalette.white.color); TextConfig regular = TextConfig(color: BasicPalette.white.color);
TextConfig tiny = regular.withFontSize(12.0); TextConfig tiny = regular.withFontSize(12.0);
@ -32,31 +35,27 @@ class MyTextBox extends TextBoxComponent {
} }
class MyGame extends BaseGame { class MyGame extends BaseGame {
MyGame() { Size screenSize;
_start();
}
void _start() async {
final Size size = await Flame.util.initialDimensions();
MyGame(this.screenSize) {
add(TextComponent('Hello, Flame', config: regular) add(TextComponent('Hello, Flame', config: regular)
..anchor = Anchor.topCenter ..anchor = Anchor.topCenter
..x = size.width / 2 ..x = screenSize.width / 2
..y = 32.0); ..y = 32.0);
add(TextComponent('center', config: tiny) add(TextComponent('center', config: tiny)
..anchor = Anchor.center ..anchor = Anchor.center
..x = size.width / 2 ..x = screenSize.width / 2
..y = size.height / 2); ..y = screenSize.height / 2);
add(TextComponent('bottomRight', config: tiny) add(TextComponent('bottomRight', config: tiny)
..anchor = Anchor.bottomRight ..anchor = Anchor.bottomRight
..x = size.width ..x = screenSize.width
..y = size.height); ..y = screenSize.height);
add(MyTextBox( add(MyTextBox(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ligula eu lectus lobortis condimentum.') 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ligula eu lectus lobortis condimentum.')
..anchor = Anchor.bottomLeft ..anchor = Anchor.bottomLeft
..y = size.height); ..y = screenSize.height);
} }
} }