mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
Move from Position to Vector2
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:flame/gestures.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/vector.dart';
|
||||
import 'package:flame/sprite_animation.dart';
|
||||
import 'package:flame/components/sprite_animation_component.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -10,7 +11,7 @@ void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Flame.images.loadAll(['creature.png', 'chopper.png']);
|
||||
|
||||
final Size size = await Flame.util.initialDimensions();
|
||||
final Vector2 size = await Flame.util.initialDimensions();
|
||||
final game = MyGame(size);
|
||||
runApp(game.widget);
|
||||
}
|
||||
@ -53,12 +54,12 @@ class MyGame extends BaseGame with TapDetector {
|
||||
addAnimation(evt.globalPosition.dx, evt.globalPosition.dy);
|
||||
}
|
||||
|
||||
MyGame(Size screenSize) {
|
||||
MyGame(Vector2 screenSize) {
|
||||
size = screenSize;
|
||||
|
||||
const s = 100.0;
|
||||
final animationComponent = SpriteAnimationComponent(s, s, animation);
|
||||
animationComponent.x = size.width / 2 - s;
|
||||
animationComponent.x = size.x / 2 - s;
|
||||
animationComponent.y = s;
|
||||
|
||||
final reversedAnimationComponent = SpriteAnimationComponent(
|
||||
@ -66,7 +67,7 @@ class MyGame extends BaseGame with TapDetector {
|
||||
s,
|
||||
animation.reversed(),
|
||||
);
|
||||
reversedAnimationComponent.x = size.width / 2;
|
||||
reversedAnimationComponent.x = size.x / 2;
|
||||
reversedAnimationComponent.y = s;
|
||||
|
||||
add(animationComponent);
|
||||
|
||||
Reference in New Issue
Block a user