Skip to content

Commit 5b755a1

Browse files
committed
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.
1 parent 34fa27a commit 5b755a1

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/body/Body.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var Axes = require('../geometry/Axes');
7171
timeScale: 1,
7272
render: {
7373
visible: true,
74+
opacity: 1,
7475
sprite: {
7576
xScale: 1,
7677
yScale: 1,

src/render/Render.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ var Vector = require('../geometry/Vector');
445445
if (options.showSleeping && body.isSleeping)
446446
c.globalAlpha = 0.5;
447447

448+
if (part.render.opacity !== 1)
449+
c.globalAlpha = part.render.opacity;
450+
451+
448452
c.translate(part.position.x, part.position.y);
449453
c.rotate(part.angle);
450454

@@ -460,7 +464,7 @@ var Vector = require('../geometry/Vector');
460464
c.rotate(-part.angle);
461465
c.translate(-part.position.x, -part.position.y);
462466

463-
if (options.showSleeping && body.isSleeping)
467+
if ((options.showSleeping && body.isSleeping) || part.render.opacity !== 1)
464468
c.globalAlpha = 1;
465469
} else {
466470
// part polygon

0 commit comments

Comments
 (0)