avocado-old/packages/graphics/renderer.js
2019-03-25 23:39:07 -05:00

47 lines
907 B
JavaScript

const PIXI = 'undefined' !== typeof window ? require('pixi.js') : undefined;
export class Renderer {
constructor(size = [0, 0], type = 'auto') {
switch (type) {
case 'auto':
this.renderer = PIXI.autoDetectRenderer(size[0], size[1]);
break;
case 'canvas':
this.renderer = new PIXI.CanvasRenderer(size[0], size[1]);
break;
case 'webgl':
this.renderer = new PIXI.WebGLRenderer(size[0], size[1]);
break;
}
}
destroy() {
this.renderer.destroy();
}
get element() {
return this.renderer.view;
}
get height() {
return this.element.height;
}
render(item, canvas) {
const canvasInternal = canvas ? canvas.internal : undefined;
this.renderer.render(item.internal, canvasInternal);
}
get size() {
return [this.width, this.height];
}
get width() {
return this.element.width;
}
}