fix some apis

This commit is contained in:
Luan Nico
2018-04-15 10:00:18 -03:00
parent 6871b2993a
commit 879b358ad3
7 changed files with 42 additions and 30 deletions

View File

@@ -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;
}