mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Fix usages
This commit is contained in:
@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/palette.dart';
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flame/extensions/vector2.dart';
|
||||
import 'package:flame/extensions/offset.dart';
|
||||
|
||||
void main() {
|
||||
final game = MyGame();
|
||||
@ -12,8 +13,8 @@ void main() {
|
||||
class MyGame extends Game with MouseMovementDetector {
|
||||
static const SPEED = 200;
|
||||
|
||||
Position position = Position(0, 0);
|
||||
Position target;
|
||||
Vector2 position = Vector2(0, 0);
|
||||
Vector2 target;
|
||||
|
||||
final Paint _blue = Paint()..color = const Color(0xFF0000FF);
|
||||
|
||||
@ -21,7 +22,7 @@ class MyGame extends Game with MouseMovementDetector {
|
||||
|
||||
@override
|
||||
void onMouseMove(event) {
|
||||
target = Position.fromOffset(event.localPosition);
|
||||
target = event.localPosition.toVector2();
|
||||
}
|
||||
|
||||
Rect _toRect() => Rect.fromLTWH(
|
||||
@ -45,9 +46,8 @@ class MyGame extends Game with MouseMovementDetector {
|
||||
_onTarget = _toRect().contains(target.toOffset());
|
||||
|
||||
if (!_onTarget) {
|
||||
final dir = target.clone().minus(position).normalize();
|
||||
|
||||
position.add(dir.times(SPEED * dt));
|
||||
final dir = (target - position).normalize();
|
||||
position += dir.times(SPEED * dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/palette.dart';
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flame/extensions/vector2.dart';
|
||||
import 'package:flame/extensions/offset.dart';
|
||||
|
||||
void main() {
|
||||
final game = MyGame();
|
||||
@ -12,12 +13,12 @@ void main() {
|
||||
class MyGame extends Game with ScrollDetector {
|
||||
static const SPEED = 200;
|
||||
|
||||
Position position = Position(0, 0);
|
||||
Position target;
|
||||
Vector2 position = Vector2(0, 0);
|
||||
Vector2 target;
|
||||
|
||||
@override
|
||||
void onScroll(event) {
|
||||
target = position.minus(Position.fromOffset(event.scrollDelta));
|
||||
target = position.minus(event.scrollDelta.toVector2());
|
||||
}
|
||||
|
||||
@override
|
||||
@ -36,9 +37,8 @@ class MyGame extends Game with ScrollDetector {
|
||||
@override
|
||||
void update(double dt) {
|
||||
if (target != null) {
|
||||
final dir = target.clone().minus(position).normalize();
|
||||
|
||||
position.add(dir.times(SPEED * dt));
|
||||
final dir = (target - position).normalize();
|
||||
position += dir.times(SPEED * dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flame/components/sprite_component.dart';
|
||||
import 'package:flame/extensions/vector2.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/components/isometric_tile_map_component.dart';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flame/sprite.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -11,7 +11,7 @@ import 'package:flutter/material.dart';
|
||||
const x = 500.0;
|
||||
const y = 500.0;
|
||||
const s = 64;
|
||||
final topLeft = Position(x, y);
|
||||
final topLeft = Vector2(x, y);
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@ -226,7 +226,7 @@ game.add(
|
||||
ParticleComponent(
|
||||
particle: SpriteParticle(
|
||||
sprite: Sprite('sprite.png'),
|
||||
size: Position(64, 64),
|
||||
size: Vector2(64, 64),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@ -15,6 +15,6 @@ extension OffsetExtension on Offset {
|
||||
/// Creates a [Point] from the [Offset]
|
||||
Point toPoint() => Point(dx, dy);
|
||||
|
||||
/// Creates a [Rect] starting in origo and going the [Offset]
|
||||
/// Creates a [Rect] starting in origin and going the [Offset]
|
||||
Rect toRect() => Rect.fromLTWH(0, 0, dx, dy);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user