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

View File

@ -0,0 +1,42 @@
import 'dart:ui';
import 'component.dart';
import '../sprite.dart';
class AnimationComponent extends PositionComponent {
double width, height;
List<Sprite> sprites;
double stepTime = 0.1;
double lifeTime = 0.0;
AnimationComponent.spriteList(this.width, this.height, this.sprites, { this.stepTime, this.lifeTime });
AnimationComponent.sequenced(this.width, this.height, String imagePath, int amount, { double textureX = 0.0, double textureY = 0.0, double textureWidth = -1.0, double textureHeight = -1.0}) {
angle = 0.0;
if (textureWidth == -1) {
textureWidth = this.width;
}
if (textureHeight == -1) {
textureHeight = this.height;
}
sprites = new List<Sprite>(amount);
for (var i = 0; i < amount; i++) {
sprites[i] = new Sprite(imagePath, x: textureX + i*textureWidth, y: textureY, width: textureWidth, height: textureHeight);
}
}
@override
void render(Canvas canvas) {
prepareCanvas(canvas);
int i = (lifeTime / stepTime).round();
sprites[i % sprites.length].render(canvas, width, height);
}
@override
void update(double t) {
this.lifeTime += t;
}
}