Skip to content

Commit 778b691

Browse files
authored
Merge pull request #5683 from yashlamba/image-alpha
Fixed background transparency with Images
2 parents 43baa48 + 976a3e1 commit 778b691

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)