mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Fixing release mode on examples that needed screenSize
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user