0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-28 14:09:01 -05:00

fixed RenderPixi for compound bodies

This commit is contained in:
liabru 2015-04-21 21:16:26 +01:00
parent b34669ed69
commit 6679b9c6c5

View file

@ -369,25 +369,35 @@ var RenderPixi = {};
var _createBodyPrimitive = function(render, body) { var _createBodyPrimitive = function(render, body) {
var bodyRender = body.render, var bodyRender = body.render,
options = render.options, options = render.options,
primitive = new PIXI.Graphics(); primitive = new PIXI.Graphics(),
fillStyle = Common.colorToNumber(bodyRender.fillStyle),
strokeStyle = Common.colorToNumber(bodyRender.strokeStyle),
strokeStyleIndicator = Common.colorToNumber(bodyRender.strokeStyle),
strokeStyleWireframe = Common.colorToNumber('#bbb'),
strokeStyleWireframeIndicator = Common.colorToNumber('#CD5C5C'),
part;
primitive.clear(); primitive.clear();
// handle compound parts
for (var k = body.parts.length > 1 ? 1 : 0; k < body.parts.length; k++) {
part = body.parts[k];
if (!options.wireframes) { if (!options.wireframes) {
primitive.beginFill(Common.colorToNumber(bodyRender.fillStyle), 1); primitive.beginFill(fillStyle, 1);
primitive.lineStyle(body.render.lineWidth, Common.colorToNumber(bodyRender.strokeStyle), 1); primitive.lineStyle(bodyRender.lineWidth, strokeStyle, 1);
} else { } else {
primitive.beginFill(0, 0); primitive.beginFill(0, 0);
primitive.lineStyle(1, Common.colorToNumber('#bbb'), 1); primitive.lineStyle(1, strokeStyleWireframe, 1);
} }
primitive.moveTo(body.vertices[0].x - body.position.x, body.vertices[0].y - body.position.y); primitive.moveTo(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
for (var j = 1; j < body.vertices.length; j++) { for (var j = 1; j < part.vertices.length; j++) {
primitive.lineTo(body.vertices[j].x - body.position.x, body.vertices[j].y - body.position.y); primitive.lineTo(part.vertices[j].x - body.position.x, part.vertices[j].y - body.position.y);
} }
primitive.lineTo(body.vertices[0].x - body.position.x, body.vertices[0].y - body.position.y); primitive.lineTo(part.vertices[0].x - body.position.x, part.vertices[0].y - body.position.y);
primitive.endFill(); primitive.endFill();
@ -396,17 +406,18 @@ var RenderPixi = {};
primitive.beginFill(0, 0); primitive.beginFill(0, 0);
if (options.wireframes) { if (options.wireframes) {
primitive.lineStyle(1, Common.colorToNumber('#CD5C5C'), 1); primitive.lineStyle(1, strokeStyleWireframeIndicator, 1);
} else { } else {
primitive.lineStyle(1, Common.colorToNumber(body.render.strokeStyle)); primitive.lineStyle(1, strokeStyleIndicator);
} }
primitive.moveTo(0, 0); primitive.moveTo(part.position.x - body.position.x, part.position.y - body.position.y);
primitive.lineTo(((body.vertices[0].x + body.vertices[body.vertices.length-1].x) / 2) - body.position.x, primitive.lineTo(((part.vertices[0].x + part.vertices[part.vertices.length-1].x) / 2 - body.position.x),
((body.vertices[0].y + body.vertices[body.vertices.length-1].y) / 2) - body.position.y); ((part.vertices[0].y + part.vertices[part.vertices.length-1].y) / 2 - body.position.y));
primitive.endFill(); primitive.endFill();
} }
}
return primitive; return primitive;
}; };