Skip to content

Commit

Permalink
Some fixes in pixi.js v3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
upisfree committed May 21, 2015
1 parent 419d2ad commit 96735dd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script type="text/javascript" src="./js/lib/decomp.js"></script>

<!-- only required if using Matter.RenderPixi -->
<script type="text/javascript" src="./js/lib/pixi.dev.js"></script>
<script type="text/javascript" src="./js/lib/pixi.js"></script>

<!-- matter lib edge master version -->
<script type="text/javascript" src="./js/lib/matter-dev.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="robots" content="noindex">

<!-- only required if using Matter.RenderPixi -->
<script type="text/javascript" src="./js/lib/pixi.dev.js"></script>
<script type="text/javascript" src="./js/lib/pixi.js"></script>

<!-- matter lib v0.8.0 -->
<script type="text/javascript" src="./js/lib/matter-0.8.0.js"></script>
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions demo/js/lib/pixi.js.map

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions src/render/RenderPixi.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var RenderPixi = {};
// init pixi
render.context = new PIXI.WebGLRenderer(render.options.width, render.options.height, {
view: render.canvas,
autoResize: true,
transparent: transparent,
antialias: true,
backgroundColor: options.background
Expand All @@ -72,8 +71,8 @@ var RenderPixi = {};
render.primitives = {};

// use a sprite batch for performance
render.bodies = new PIXI.Container();
render.container.addChild(render.bodies);
render.spriteContainer = new PIXI.Container();
render.container.addChild(render.spriteContainer);

// insert canvas
if (Common.isElement(render.element)) {
Expand All @@ -96,16 +95,16 @@ var RenderPixi = {};
*/
RenderPixi.clear = function(render) {
var container = render.container,
bodies = render.bodies;
spriteContainer = render.spriteContainer;

// clear stage container
while (container.children[0]) {
container.removeChild(container.children[0]);
}

// clear sprite batch
while (bodies.children[0]) {
bodies.removeChild(bodies.children[0]);
while (spriteContainer.children[0]) {
spriteContainer.removeChild(spriteContainer.children[0]);
}

var bgSprite = render.sprites['bg-0'];
Expand All @@ -121,7 +120,7 @@ var RenderPixi = {};
container.addChildAt(bgSprite, 0);

// add sprite batch back into container
render.container.addChild(render.bodies);
render.container.addChild(render.spriteContainer);

// reset background state
render.currentBackground = null;
Expand Down Expand Up @@ -232,7 +231,7 @@ var RenderPixi = {};
for (i = 0; i < constraints.length; i++)
RenderPixi.constraint(engine, constraints[i]);

context.render(container); // render just render.bodies?
context.render(container);
};


Expand Down Expand Up @@ -303,15 +302,15 @@ var RenderPixi = {};
if (bodyRender.sprite && bodyRender.sprite.texture) {
var spriteId = 'b-' + body.id,
sprite = render.sprites[spriteId],
bodies = render.bodies;
spriteContainer = render.spriteContainer;

// initialise body sprite if not existing
if (!sprite)
sprite = render.sprites[spriteId] = _createBodySprite(render, body);

// add to scene graph if not already there
if (Common.indexOf(bodies.children, sprite) === -1)
bodies.addChild(sprite);
if (Common.indexOf(spriteContainer.children, sprite) === -1)
spriteContainer.addChild(sprite);

// update body sprite
sprite.position.x = body.position.x;
Expand Down Expand Up @@ -369,7 +368,7 @@ var RenderPixi = {};
* @param {body} body
* @return {PIXI.Graphics} graphics
*/
var _createBodyPrimitive = function(render, body) { // TODO: use canvas to create sprite, not PIXI.Graphics
var _createBodyPrimitive = function(render, body) {
var bodyRender = body.render,
options = render.options,
primitive = new PIXI.Graphics(),
Expand Down

0 comments on commit 96735dd

Please sign in to comment.