diff --git a/doc/examples/animations/lib/main.dart b/doc/examples/animations/lib/main.dart index e2073ce3a..3369b1eca 100644 --- a/doc/examples/animations/lib/main.dart +++ b/doc/examples/animations/lib/main.dart @@ -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); diff --git a/doc/examples/aseprite/lib/main.dart b/doc/examples/aseprite/lib/main.dart index cf2a635e5..10b0b6c53 100644 --- a/doc/examples/aseprite/lib/main.dart +++ b/doc/examples/aseprite/lib/main.dart @@ -4,22 +4,25 @@ import 'package:flame/animation.dart' as flame_animation; import 'package:flame/components/animation_component.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 { - MyGame() { + Size screenSize; + + MyGame(this.screenSize) { _start(); } void _start() async { - final Size size = await Flame.util.initialDimensions(); - final animation = await flame_animation.Animation.fromAsepriteData( 'chopper.png', 'chopper.json'); final animationComponent = AnimationComponent(200, 200, animation); - animationComponent.x = (size.width / 2) - 100; - animationComponent.y = (size.height / 2) - 100; + animationComponent.x = (screenSize.width / 2) - 100; + animationComponent.y = (screenSize.height / 2) - 100; add(animationComponent); } diff --git a/doc/examples/sound/lib/main.dart b/doc/examples/sound/lib/main.dart index 6a1a961e1..0672c2fdc 100644 --- a/doc/examples/sound/lib/main.dart +++ b/doc/examples/sound/lib/main.dart @@ -3,7 +3,10 @@ import 'package:flame/game.dart'; import 'package:flame/components/component.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 { final Size gameSize; @@ -37,19 +40,20 @@ class Ball extends PositionComponent { } class MyGame extends BaseGame { - MyGame() { + Size screenSize; + + MyGame(this.screenSize) { _start(); } void _start() async { - final Size size = await Flame.util.initialDimensions(); Flame.audio.disableLog(); Flame.audio.load('boin.mp3'); Flame.audio.loop('music.mp3', volume: 0.4); - add(Ball(size) - ..y = (size.height / 2) - 50 + add(Ball(this.screenSize) + ..y = (this.screenSize.height / 2) - 50 ..width = 100 ..height = 100); } diff --git a/doc/examples/text/lib/main.dart b/doc/examples/text/lib/main.dart index 93a41cb94..bc3092b33 100644 --- a/doc/examples/text/lib/main.dart +++ b/doc/examples/text/lib/main.dart @@ -9,7 +9,10 @@ import 'package:flame/palette.dart'; import 'package:flame/text_config.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 tiny = regular.withFontSize(12.0); @@ -32,31 +35,27 @@ class MyTextBox extends TextBoxComponent { } class MyGame extends BaseGame { - MyGame() { - _start(); - } - - void _start() async { - final Size size = await Flame.util.initialDimensions(); + Size screenSize; + MyGame(this.screenSize) { add(TextComponent('Hello, Flame', config: regular) ..anchor = Anchor.topCenter - ..x = size.width / 2 + ..x = screenSize.width / 2 ..y = 32.0); add(TextComponent('center', config: tiny) ..anchor = Anchor.center - ..x = size.width / 2 - ..y = size.height / 2); + ..x = screenSize.width / 2 + ..y = screenSize.height / 2); add(TextComponent('bottomRight', config: tiny) ..anchor = Anchor.bottomRight - ..x = size.width - ..y = size.height); + ..x = screenSize.width + ..y = screenSize.height); add(MyTextBox( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eget ligula eu lectus lobortis condimentum.') ..anchor = Anchor.bottomLeft - ..y = size.height); + ..y = screenSize.height); } }