feat: AnimationView

This commit is contained in:
cha0s 2019-03-19 18:05:58 -05:00
parent a4b0c9dd22
commit 042e6ae071
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,49 @@
import {hasGraphics} from './has-graphics';
import {Container} from './container';
import {Image} from './image';
import {Renderable} from './renderable';
import {Sprite} from './sprite';
export class AnimationView extends Renderable {
constructor(animation) {
super();
this.animation = animation;
this.container = new Container();
if (hasGraphics) {
Image.load(this.animation.imageUri).then((image) => {
this.sprite = new Sprite(image);
this.container.addChild(this.sprite);
this.resetSourceRectangle();
});
animation.on(['directionChanged', 'indexChanged'], () => {
if (this.sprite) {
this.resetSourceRectangle();
}
});
}
}
destroy() {
if (this.sprite) {
this.sprite.destroy();
}
}
get internal() {
return this.container.internal;
}
reset() {
this.animation.reset();
}
resetSourceRectangle() {
this.sprite.sourceRectangle = this.animation.sourceRectangle;
}
tick() {
this.animation.tick();
}
}

View File

@ -1,3 +1,4 @@
export {AnimationView} from './animation-view';
export {Color} from './color'; export {Color} from './color';
export {Container} from './container'; export {Container} from './container';
export {hasGraphics} from './has-graphics'; export {hasGraphics} from './has-graphics';