mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
Updated pixi.js to v3
This commit is contained in:
parent
95ae911ed6
commit
419d2addca
2 changed files with 25930 additions and 12939 deletions
38826
demo/js/lib/pixi.dev.js
38826
demo/js/lib/pixi.dev.js
File diff suppressed because it is too large
Load diff
|
@ -46,11 +46,15 @@ var RenderPixi = {};
|
||||||
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.canvas, transparent, true);
|
render.context = new PIXI.WebGLRenderer(render.options.width, render.options.height, {
|
||||||
|
view: render.canvas,
|
||||||
|
autoResize: true,
|
||||||
|
transparent: transparent,
|
||||||
|
antialias: true,
|
||||||
|
backgroundColor: options.background
|
||||||
|
});
|
||||||
render.canvas = render.context.view;
|
render.canvas = render.context.view;
|
||||||
render.container = new PIXI.DisplayObjectContainer();
|
render.container = new PIXI.Container();
|
||||||
render.stage = new PIXI.Stage();
|
|
||||||
render.stage.addChild(render.container);
|
|
||||||
render.bounds = render.bounds || {
|
render.bounds = render.bounds || {
|
||||||
min: {
|
min: {
|
||||||
x: 0,
|
x: 0,
|
||||||
|
@ -68,8 +72,8 @@ var RenderPixi = {};
|
||||||
render.primitives = {};
|
render.primitives = {};
|
||||||
|
|
||||||
// use a sprite batch for performance
|
// use a sprite batch for performance
|
||||||
render.spriteBatch = new PIXI.SpriteBatch();
|
render.bodies = new PIXI.Container();
|
||||||
render.container.addChild(render.spriteBatch);
|
render.container.addChild(render.bodies);
|
||||||
|
|
||||||
// insert canvas
|
// insert canvas
|
||||||
if (Common.isElement(render.element)) {
|
if (Common.isElement(render.element)) {
|
||||||
|
@ -92,7 +96,7 @@ var RenderPixi = {};
|
||||||
*/
|
*/
|
||||||
RenderPixi.clear = function(render) {
|
RenderPixi.clear = function(render) {
|
||||||
var container = render.container,
|
var container = render.container,
|
||||||
spriteBatch = render.spriteBatch;
|
bodies = render.bodies;
|
||||||
|
|
||||||
// clear stage container
|
// clear stage container
|
||||||
while (container.children[0]) {
|
while (container.children[0]) {
|
||||||
|
@ -100,8 +104,8 @@ var RenderPixi = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear sprite batch
|
// clear sprite batch
|
||||||
while (spriteBatch.children[0]) {
|
while (bodies.children[0]) {
|
||||||
spriteBatch.removeChild(spriteBatch.children[0]);
|
bodies.removeChild(bodies.children[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var bgSprite = render.sprites['bg-0'];
|
var bgSprite = render.sprites['bg-0'];
|
||||||
|
@ -114,10 +118,10 @@ var RenderPixi = {};
|
||||||
// set background sprite
|
// set background sprite
|
||||||
render.sprites['bg-0'] = bgSprite;
|
render.sprites['bg-0'] = bgSprite;
|
||||||
if (bgSprite)
|
if (bgSprite)
|
||||||
spriteBatch.addChildAt(bgSprite, 0);
|
container.addChildAt(bgSprite, 0);
|
||||||
|
|
||||||
// add sprite batch back into container
|
// add sprite batch back into container
|
||||||
render.container.addChild(render.spriteBatch);
|
render.container.addChild(render.bodies);
|
||||||
|
|
||||||
// reset background state
|
// reset background state
|
||||||
render.currentBackground = null;
|
render.currentBackground = null;
|
||||||
|
@ -141,11 +145,11 @@ var RenderPixi = {};
|
||||||
if (isColor) {
|
if (isColor) {
|
||||||
// if solid background color
|
// if solid background color
|
||||||
var color = Common.colorToNumber(background);
|
var color = Common.colorToNumber(background);
|
||||||
render.stage.setBackgroundColor(color);
|
render.context.backgroundColor = color;
|
||||||
|
|
||||||
// remove background sprite if existing
|
// remove background sprite if existing
|
||||||
if (bgSprite)
|
if (bgSprite)
|
||||||
render.spriteBatch.removeChild(bgSprite);
|
render.container.removeChild(bgSprite);
|
||||||
} else {
|
} else {
|
||||||
// initialise background sprite if needed
|
// initialise background sprite if needed
|
||||||
if (!bgSprite) {
|
if (!bgSprite) {
|
||||||
|
@ -154,7 +158,7 @@ var RenderPixi = {};
|
||||||
bgSprite = render.sprites['bg-0'] = new PIXI.Sprite(texture);
|
bgSprite = render.sprites['bg-0'] = new PIXI.Sprite(texture);
|
||||||
bgSprite.position.x = 0;
|
bgSprite.position.x = 0;
|
||||||
bgSprite.position.y = 0;
|
bgSprite.position.y = 0;
|
||||||
render.spriteBatch.addChildAt(bgSprite, 0);
|
render.container.addChildAt(bgSprite, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +175,6 @@ var RenderPixi = {};
|
||||||
var render = engine.render,
|
var render = engine.render,
|
||||||
world = engine.world,
|
world = engine.world,
|
||||||
context = render.context,
|
context = render.context,
|
||||||
stage = render.stage,
|
|
||||||
container = render.container,
|
container = render.container,
|
||||||
options = render.options,
|
options = render.options,
|
||||||
bodies = Composite.allBodies(world),
|
bodies = Composite.allBodies(world),
|
||||||
|
@ -229,7 +232,7 @@ var RenderPixi = {};
|
||||||
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(stage);
|
context.render(container); // render just render.bodies?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,15 +303,15 @@ var RenderPixi = {};
|
||||||
if (bodyRender.sprite && bodyRender.sprite.texture) {
|
if (bodyRender.sprite && bodyRender.sprite.texture) {
|
||||||
var spriteId = 'b-' + body.id,
|
var spriteId = 'b-' + body.id,
|
||||||
sprite = render.sprites[spriteId],
|
sprite = render.sprites[spriteId],
|
||||||
spriteBatch = render.spriteBatch;
|
bodies = render.bodies;
|
||||||
|
|
||||||
// initialise body sprite if not existing
|
// initialise body sprite if not existing
|
||||||
if (!sprite)
|
if (!sprite)
|
||||||
sprite = render.sprites[spriteId] = _createBodySprite(render, body);
|
sprite = render.sprites[spriteId] = _createBodySprite(render, body);
|
||||||
|
|
||||||
// add to scene graph if not already there
|
// add to scene graph if not already there
|
||||||
if (Common.indexOf(spriteBatch.children, sprite) === -1)
|
if (Common.indexOf(bodies.children, sprite) === -1)
|
||||||
spriteBatch.addChild(sprite);
|
bodies.addChild(sprite);
|
||||||
|
|
||||||
// update body sprite
|
// update body sprite
|
||||||
sprite.position.x = body.position.x;
|
sprite.position.x = body.position.x;
|
||||||
|
@ -366,7 +369,7 @@ var RenderPixi = {};
|
||||||
* @param {body} body
|
* @param {body} body
|
||||||
* @return {PIXI.Graphics} graphics
|
* @return {PIXI.Graphics} graphics
|
||||||
*/
|
*/
|
||||||
var _createBodyPrimitive = function(render, body) {
|
var _createBodyPrimitive = function(render, body) { // TODO: use canvas to create sprite, not PIXI.Graphics
|
||||||
var bodyRender = body.render,
|
var bodyRender = body.render,
|
||||||
options = render.options,
|
options = render.options,
|
||||||
primitive = new PIXI.Graphics(),
|
primitive = new PIXI.Graphics(),
|
||||||
|
|
Loading…
Reference in a new issue