36 lines
631 B
JavaScript
36 lines
631 B
JavaScript
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];
|
|
}
|
|
|
|
destroy() {
|
|
this.sprite.destroy();
|
|
}
|
|
|
|
get internal() {
|
|
return this.sprite;
|
|
}
|
|
|
|
get image() {
|
|
return this._image;
|
|
}
|
|
|
|
set sourceRectangle(rectangle) {
|
|
this._image.texture.frame = {
|
|
x: rectangle[0],
|
|
y: rectangle[1],
|
|
width: rectangle[2],
|
|
height: rectangle[3],
|
|
};
|
|
}
|
|
|
|
}
|