0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-17 12:42:17 -05:00

allow passing of pixi objects to Matter.RenderPixi at creation, closes #193

This commit is contained in:
liabru 2016-02-07 15:47:23 +00:00
parent 99dd6c518a
commit dbdabcca65

View file

@ -1,5 +1,6 @@
/** /**
* See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples). * The `Matter.RenderPixi` module is an example renderer using pixi.js.
* See also `Matter.Render` for a canvas based renderer.
* *
* @class RenderPixi * @class RenderPixi
*/ */
@ -24,6 +25,10 @@ var Common = require('../core/Common');
controller: RenderPixi, controller: RenderPixi,
element: null, element: null,
canvas: null, canvas: null,
renderer: null,
container: null,
spriteContainer: null,
pixiOptions: null,
options: { options: {
width: 800, width: 800,
height: 600, height: 600,
@ -50,17 +55,19 @@ var Common = require('../core/Common');
transparent = !render.options.wireframes && render.options.background === 'transparent'; transparent = !render.options.wireframes && render.options.background === 'transparent';
// init pixi // init pixi
render.context = new PIXI.WebGLRenderer(render.options.width, render.options.height, { render.pixiOptions = render.pixiOptions || {
view: render.canvas, view: render.canvas,
transparent: transparent, transparent: transparent,
antialias: true, antialias: true,
backgroundColor: options.background backgroundColor: options.background
}); };
render.canvas = render.context.view; render.renderer = render.renderer || new PIXI.WebGLRenderer(render.options.width, render.options.height, render.pixiOptions);
render.container = new PIXI.Container(); render.container = render.container || new PIXI.Container();
render.spriteContainer = render.spriteContainer || new PIXI.Container();
render.canvas = render.canvas || render.renderer.view;
render.bounds = render.bounds || { render.bounds = render.bounds || {
min: { min: {
x: 0, x: 0,
y: 0 y: 0
}, },
@ -76,7 +83,6 @@ var Common = require('../core/Common');
render.primitives = {}; render.primitives = {};
// use a sprite batch for performance // use a sprite batch for performance
render.spriteContainer = new PIXI.Container();
render.container.addChild(render.spriteContainer); render.container.addChild(render.spriteContainer);
// insert canvas // insert canvas
@ -149,7 +155,7 @@ var Common = require('../core/Common');
if (isColor) { if (isColor) {
// if solid background color // if solid background color
var color = Common.colorToNumber(background); var color = Common.colorToNumber(background);
render.context.backgroundColor = color; render.renderer.backgroundColor = color;
// remove background sprite if existing // remove background sprite if existing
if (bgSprite) if (bgSprite)
@ -178,7 +184,7 @@ var Common = require('../core/Common');
RenderPixi.world = function(engine) { RenderPixi.world = function(engine) {
var render = engine.render, var render = engine.render,
world = engine.world, world = engine.world,
context = render.context, renderer = render.renderer,
container = render.container, container = render.container,
options = render.options, options = render.options,
bodies = Composite.allBodies(world), bodies = Composite.allBodies(world),
@ -236,7 +242,7 @@ var Common = require('../core/Common');
for (i = 0; i < constraints.length; i++) for (i = 0; i < constraints.length; i++)
RenderPixi.constraint(engine, constraints[i]); RenderPixi.constraint(engine, constraints[i]);
context.render(container); renderer.render(container);
}; };