mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-11 18:11:12 +08:00
fix some apis
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:ui';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
@@ -10,10 +11,6 @@ class Sprite {
|
||||
|
||||
static final Paint paint = new Paint()..color = Colors.white;
|
||||
|
||||
Sprite.fromImage(this.image) {
|
||||
this.src = new Rect.fromLTWH(0.0, 0.0, image.width.toDouble(), image.height.toDouble());
|
||||
}
|
||||
|
||||
Sprite(String fileName, {double x = 0.0, double y = 0.0, double width = -1.0, double height = -1.0}) {
|
||||
Flame.images.load(fileName).then((img) {
|
||||
if (width == -1.0) {
|
||||
@@ -27,6 +24,21 @@ class Sprite {
|
||||
});
|
||||
}
|
||||
|
||||
Sprite.fromImage(this.image, {double x = 0.0, double y = 0.0, double width = -1.0, double height = -1.0}) {
|
||||
if (width == -1.0) {
|
||||
width = image.width.toDouble();
|
||||
}
|
||||
if (height == -1.0) {
|
||||
height = image.height.toDouble();
|
||||
}
|
||||
this.src = new Rect.fromLTWH(x, y, width, height);
|
||||
}
|
||||
|
||||
static Future<Sprite> loadSprite(String fileName, {double x = 0.0, double y = 0.0, double width = -1.0, double height = -1.0}) async {
|
||||
Image image = await Flame.images.load(fileName);
|
||||
return new Sprite.fromImage(image, x: x, y: y, width: width, height: height);
|
||||
}
|
||||
|
||||
bool loaded() {
|
||||
return image != null && src != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user