mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +08:00
bounds -> src for Sprite
This commit is contained in:
@ -31,7 +31,7 @@ class NineTileBox {
|
|||||||
/// If [destTileSize] is not provided, the evaluated [tileSize] is used instead
|
/// If [destTileSize] is not provided, the evaluated [tileSize] is used instead
|
||||||
/// (so no scaling happens).
|
/// (so no scaling happens).
|
||||||
NineTileBox(this.sprite, {int tileSize, int destTileSize}) {
|
NineTileBox(this.sprite, {int tileSize, int destTileSize}) {
|
||||||
this.tileSize = tileSize ?? sprite.bounds.width.toInt();
|
this.tileSize = tileSize ?? sprite.src.width.toInt();
|
||||||
this.destTileSize = destTileSize ?? tileSize;
|
this.destTileSize = destTileSize ?? tileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ class NineTileBox {
|
|||||||
double get _destTileSizeDouble => destTileSize.toDouble();
|
double get _destTileSizeDouble => destTileSize.toDouble();
|
||||||
|
|
||||||
void _drawTile(Canvas c, Rect dest, int i, int j) {
|
void _drawTile(Canvas c, Rect dest, int i, int j) {
|
||||||
final xSrc = sprite.bounds.left + _tileSizeDouble * i;
|
final xSrc = sprite.src.left + _tileSizeDouble * i;
|
||||||
final ySrc = sprite.bounds.top + _tileSizeDouble * j;
|
final ySrc = sprite.src.top + _tileSizeDouble * j;
|
||||||
final src = Rect.fromLTWH(xSrc, ySrc, _tileSizeDouble, _tileSizeDouble);
|
final src = Rect.fromLTWH(xSrc, ySrc, _tileSizeDouble, _tileSizeDouble);
|
||||||
c.drawImageRect(sprite.image, src, dest, BasicPalette.white.paint);
|
c.drawImageRect(sprite.image, src, dest, BasicPalette.white.paint);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,15 +7,15 @@ import 'palette.dart';
|
|||||||
class Sprite {
|
class Sprite {
|
||||||
Paint paint = BasicPalette.white.paint;
|
Paint paint = BasicPalette.white.paint;
|
||||||
Image image;
|
Image image;
|
||||||
Rect bounds;
|
Rect src;
|
||||||
|
|
||||||
Sprite(
|
Sprite(
|
||||||
this.image, {
|
this.image, {
|
||||||
Vector2 position,
|
Vector2 srcPosition,
|
||||||
Vector2 size,
|
Vector2 size,
|
||||||
}) : assert(image != null, "image can't be null") {
|
}) : assert(image != null, "image can't be null") {
|
||||||
size ??= Vector2(image.width.toDouble(), image.height.toDouble());
|
size ??= Vector2(image.width.toDouble(), image.height.toDouble());
|
||||||
this.position = position;
|
this.srcPosition = srcPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
double get _imageWidth => image.width.toDouble();
|
double get _imageWidth => image.width.toDouble();
|
||||||
@ -24,12 +24,12 @@ class Sprite {
|
|||||||
|
|
||||||
Vector2 get originalSize => Vector2(_imageWidth, _imageHeight);
|
Vector2 get originalSize => Vector2(_imageWidth, _imageHeight);
|
||||||
|
|
||||||
Vector2 get size => Vector2(bounds.width, bounds.height);
|
Vector2 get size => Vector2(src.width, src.height);
|
||||||
|
|
||||||
Vector2 get position => bounds.topLeft.toVector2();
|
Vector2 get srcPosition => src.topLeft.toVector2();
|
||||||
|
|
||||||
set position(Vector2 position) {
|
set srcPosition(Vector2 position) {
|
||||||
bounds = (position ?? Vector2.zero()).toPositionedRect(size);
|
src = (position ?? Vector2.zero()).toPositionedRect(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders this Sprite on the position [p], scaled by the [scale] factor provided.
|
/// Renders this Sprite on the position [p], scaled by the [scale] factor provided.
|
||||||
@ -88,6 +88,6 @@ class Sprite {
|
|||||||
Rect dst, {
|
Rect dst, {
|
||||||
Paint overridePaint,
|
Paint overridePaint,
|
||||||
}) {
|
}) {
|
||||||
canvas.drawImageRect(image, bounds, dst, overridePaint ?? paint);
|
canvas.drawImageRect(image, src, dst, overridePaint ?? paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user