avocado-old/packages/graphics/renderer.js

47 lines
907 B
JavaScript
Raw Normal View History

2019-03-18 20:06:47 -05:00
const PIXI = 'undefined' !== typeof window ? require('pixi.js') : undefined;
export class Renderer {
2019-03-25 23:39:07 -05:00
constructor(size = [0, 0], type = 'auto') {
2019-03-18 20:06:47 -05:00
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;
2019-03-25 18:54:09 -05:00
case 'webgl':
2019-03-25 23:39:07 -05:00
this.renderer = new PIXI.WebGLRenderer(size[0], size[1]);
2019-03-18 20:06:47 -05:00
break;
}
}
destroy() {
this.renderer.destroy();
}
get element() {
return this.renderer.view;
}
get height() {
return this.element.height;
}
2019-03-25 10:14:55 -05:00
render(item, canvas) {
const canvasInternal = canvas ? canvas.internal : undefined;
this.renderer.render(item.internal, canvasInternal);
2019-03-18 20:06:47 -05:00
}
get size() {
return [this.width, this.height];
}
get width() {
return this.element.width;
}
}