]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/render.js
a2e30203639355569251ded345adda2b9a83c1e0
1 import { System
} from '@serpentity/serpentity';
3 import RenderableNode
from '../nodes/renderable';
6 kNoPixiError: 'No pixi application passed to render system. Make sure you set the `application` key in the config object when initializing.'
10 * Renders renderable objects using pixi
12 * @extends {external:Serpentity.System}
14 * @param {object} config a configuration object to extend.
16 export default class RenderSystem
extends System
{
18 constructor(config
= {}) {
23 * The node collection of renderable entities
25 * @property {external:Serpentity.NodeCollection} renderables
27 * @memberof RenderSystem
29 this.renderables
= null;
32 * The pixi engine we will use to render
34 * @property {external:PixiJs.Application} renderables
36 * @memberof RenderSystem
38 this._application
= config
.application
;
40 if (!this._application
) {
41 throw new Error(internals
.kNoPixiError
);
46 * Initializes system when added. Requests renderable nodes and
47 * attaches to event listeners to add / remove them to pixi stage
50 * @memberof RenderSystem
52 * @param {external:Serpentity.Engine} engine the serpentity engine to
53 * which we are getting added
57 this.renderables
= engine
.getNodes(RenderableNode
);
58 this.renderables
.on('nodeAdded', (event
) => {
60 this._application
.stage
.addChild(event
.node
.container
.container
);
62 this.renderables
.on('nodeRemoved', (event
) => {
64 this._application
.stage
.removeChild(event
.node
.container
.container
);
69 * Clears system resources when removed.
73 * @memberof RenderSystem
77 this.renderables
.removeAllListeners('nodeAdded');
78 this.renderables
.removeAllListeners('nodeRemoved');
79 this.renderables
= null;
83 * Runs on every update of the loop. Does nothing.
87 * @param {Number} currentFrameDuration the duration of the current
89 * @memberof RenderSystem
91 update(currentFrameDuration
) {}