Start v1.0 apis (sprite, animation, box2d, etc)

This commit is contained in:
Luan Nico
2017-12-02 11:17:35 -02:00
committed by feroult
parent f5442c3e4a
commit 2fa22f2f7c
7 changed files with 187 additions and 72 deletions

35
lib/sprite.dart Normal file
View File

@ -0,0 +1,35 @@
import 'dart:ui';
import 'package:flame/flame.dart';
import 'package:flutter/material.dart' show Colors;
class Sprite {
Image image;
Rect src;
static final Paint paint = new Paint()..color = Colors.white;
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) {
width = img.width as double;
}
if (height == -1.0) {
width = img.height as double;
}
this.image = img;
this.src = new Rect.fromLTWH(x, y, width, height);
});
}
bool loaded() {
return image != null && src != null;
}
void render(Canvas canvas, double width, double height) {
if (this.loaded()) {
Rect dst = new Rect.fromLTWH(0.0, 0.0, width, height);
canvas.drawImageRect(image, src, dst, paint);
}
}
}