0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

Adding the opacity attribute to be able to draw semi-transarent sprites

Just a really simple commit adding a tiny feature I think it could be useful
while, at the same time, it seems even too tiny to specifically build a
custom render just to include it.
This commit is contained in:
MatteoAvalle 2016-02-05 11:24:58 +01:00
parent 34fa27ac97
commit 5b755a1a62
2 changed files with 6 additions and 1 deletions

View file

@ -71,6 +71,7 @@ var Axes = require('../geometry/Axes');
timeScale: 1,
render: {
visible: true,
opacity: 1,
sprite: {
xScale: 1,
yScale: 1,

View file

@ -445,6 +445,10 @@ var Vector = require('../geometry/Vector');
if (options.showSleeping && body.isSleeping)
c.globalAlpha = 0.5;
if (part.render.opacity !== 1)
c.globalAlpha = part.render.opacity;
c.translate(part.position.x, part.position.y);
c.rotate(part.angle);
@ -460,7 +464,7 @@ var Vector = require('../geometry/Vector');
c.rotate(-part.angle);
c.translate(-part.position.x, -part.position.y);
if (options.showSleeping && body.isSleeping)
if ((options.showSleeping && body.isSleeping) || part.render.opacity !== 1)
c.globalAlpha = 1;
} else {
// part polygon