Masking with an p5.Renderer Object gives an error

I have a function that grabs an image out of an array an creates a mask for that image (an ellipse on a specific location):

function getMask(image, size, w, h) { var mask = createGraphics(1280, 720); var img = imgList[image]; mask.fill(100); mask.ellipse(w, h, size, size); img.mask(mask); return img; }

Running this gives me a

Uncaught TypeError: Cannot read property 'width' of undefined p5.Renderer2D._copyHelper @ p5.js:14342 p5.copy @ p5.js:20920 p5.Image.copy @ p5.js:20575 p5.Image.mask @ p5.js:20632 getMask @ sketch.js:55 // <---- this line is 'img.mask(mask)' draw @ sketch.js:63 p5.redraw @ p5.js:16075 (anonymous function) @ p5.js:11801 _runIfPreloadsAreDone @ p5.js:11718 _decrementPreload @ p5.js:11725 img.onload @ p5.js:19883

Do I need to convert mask to an PImage? How can I get this to work?


Sign In or Register to comment.