mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
Start v1.0 apis (sprite, animation, box2d, etc)
This commit is contained in:
35
lib/sprite.dart
Normal file
35
lib/sprite.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user