avocado-old/packages/graphics/sprite.js

32 lines
585 B
JavaScript
Raw Normal View History

2019-03-18 20:06:47 -05:00
const PIXI = 'undefined' !== typeof window ? require('pixi.js') : undefined;
import {Renderable} from './renderable';
export class Sprite extends Renderable {
constructor(image) {
super();
this._image = image;
this.sprite = new PIXI.Sprite(image.texture);
this.anchor = [0.5, 0.5];
}
get internal() {
return this.sprite;
2019-03-18 20:06:47 -05:00
}
get image() {
return this._image;
}
set sourceRectangle(rectangle) {
2019-03-18 20:06:47 -05:00
this._image.texture.frame = {
x: rectangle[0],
y: rectangle[1],
width: rectangle[2],
height: rectangle[3],
};
}
}