Skip to content

Commit 976a3e1

Browse files
yashlambatwo-ticks
andcommitted
Fixed background transparency with Images
Co-authored-by: TwoTicks <[email protected]>
1 parent 4b36461 commit 976a3e1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/p5.Renderer2D.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ p5.Renderer2D.prototype.background = function(...args) {
4747
this.resetMatrix();
4848

4949
if (args[0] instanceof p5.Image) {
50-
this._pInst.image(args[0], 0, 0, this.width, this.height);
50+
if (args[1] >= 0) {
51+
// set transparency of background
52+
const img = args[0];
53+
this.drawingContext.globalAlpha = args[1] / 255;
54+
this._pInst.image(img, 0, 0, this.width, this.height);
55+
} else {
56+
this._pInst.image(args[0], 0, 0, this.width, this.height);
57+
}
5158
} else {
5259
const curFill = this._getFill();
5360
// create background rect

0 commit comments

Comments
 (0)