From 5b755a1a62bc78d3c5f058c8da86da3c4532278d Mon Sep 17 00:00:00 2001 From: MatteoAvalle Date: Fri, 5 Feb 2016 11:24:58 +0100 Subject: [PATCH] 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. --- src/body/Body.js | 1 + src/render/Render.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/body/Body.js b/src/body/Body.js index f7e3ae5..0e7bf68 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -71,6 +71,7 @@ var Axes = require('../geometry/Axes'); timeScale: 1, render: { visible: true, + opacity: 1, sprite: { xScale: 1, yScale: 1, diff --git a/src/render/Render.js b/src/render/Render.js index e8f29bd..c099d29 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -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