mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Move from Position to Vector2
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'flame.dart';
|
||||
import 'position.dart';
|
||||
import 'palette.dart';
|
||||
import 'vector.dart';
|
||||
|
||||
class Sprite {
|
||||
Paint paint = BasicPalette.white.paint;
|
||||
@ -62,15 +65,15 @@ class Sprite {
|
||||
|
||||
double get _imageHeight => image.height.toDouble();
|
||||
|
||||
Position get originalSize {
|
||||
Vector2 get originalSize {
|
||||
if (!loaded()) {
|
||||
return null;
|
||||
}
|
||||
return Position(_imageWidth, _imageHeight);
|
||||
return Vector2(_imageWidth, _imageHeight);
|
||||
}
|
||||
|
||||
Position get size {
|
||||
return Position(src.width, src.height);
|
||||
Vector2 get size {
|
||||
return Vector2(src.width, src.height);
|
||||
}
|
||||
|
||||
/// Renders this Sprite on the position [p], scaled by the [scale] factor provided.
|
||||
@ -78,22 +81,21 @@ class Sprite {
|
||||
/// It renders with src size multiplied by [scale] in both directions.
|
||||
/// Anchor is on top left as default.
|
||||
/// If not loaded, does nothing.
|
||||
void renderScaled(Canvas canvas, Position p,
|
||||
void renderScaled(Canvas canvas, Vector2 p,
|
||||
{double scale = 1.0, Paint overridePaint}) {
|
||||
if (!loaded()) {
|
||||
return;
|
||||
}
|
||||
renderPosition(canvas, p,
|
||||
size: size.times(scale), overridePaint: overridePaint);
|
||||
renderPosition(canvas, p, size: size * scale, overridePaint: overridePaint);
|
||||
}
|
||||
|
||||
void renderPosition(Canvas canvas, Position p,
|
||||
{Position size, Paint overridePaint}) {
|
||||
void renderPosition(Canvas canvas, Vector2 p,
|
||||
{Vector2 size, Paint overridePaint}) {
|
||||
if (!loaded()) {
|
||||
return;
|
||||
}
|
||||
size ??= this.size;
|
||||
renderRect(canvas, Position.rectFrom(p, size),
|
||||
renderRect(canvas, VectorUtil.rectFrom(p, size),
|
||||
overridePaint: overridePaint);
|
||||
}
|
||||
|
||||
@ -112,8 +114,8 @@ class Sprite {
|
||||
///
|
||||
/// If [size] is not provided, the original size of the src image is used.
|
||||
/// If the asset is not yet loaded, it does nothing.
|
||||
void renderCentered(Canvas canvas, Position p,
|
||||
{Position size, Paint overridePaint}) {
|
||||
void renderCentered(Canvas canvas, Vector2 p,
|
||||
{Vector2 size, Paint overridePaint}) {
|
||||
if (!loaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user