Hello! Tried to get this solved on Discord but to no avail.
Messages below:
What’s the right way to make a mask that’s like a “spotlight”, where there’s like black everywhere, but a little circle that you can position that will cut a hole in that black
Totally stumped on this kind of inverse mask
I am starting to think I need to dynamically render an image using canvas and set that to the texture or something…?
var canvas = document.createElement('canvas');
var context = canvas.getContext("2d");
context.arc(50, 50, 30, 0, 2 * Math.PI);
context.fill();
var img = new Image();
img.src = canvas.toDataURL(); document.body.appendChild(img);
context.clearRect(0, 0, canvas.width, canvas.height);
Ah shoot, and I need the portion inside the spotlight to be clickable, but the black portion to not, seems like useInput just takes the bounding rect to eat inputs
Aight so my janky thing for now is to generate 4 rectangles to create a rectangular hole where input works, but this seems super wrong lmao, especially since I am showing the user a clickable ellipse
Steven — 06/02/2022
I would use an element or html cutout and on every click, do a simple circle check to see if its in done in the cut out
Bogden — 06/02/2022
How would I still pass the click through to other stuff behind it though? The circle check would eat the input event right?
Steven — Yesterday at 12:42 AM
Have a custom click event for everything else to listen for
Bogden — Yesterday at 8:50 AM
That would mean giving up all of the benefits from using the element input system right? Like bubbling to parents, stopping propagation, blocking input from elements behind other elements, etc right?
Steven — Yesterday at 2:10 PM
Hmm , if you need it to work with UI elements, I would create the circle cutout as a playcanvas ui elements instead and do the blocking at that level
You have the top most UI element (that is in front of everything), detect all the standard input events. Check if its out of circle, stop the propergation
Bogden — Yesterday at 3:51 PM
Doesn’t that only work if that topmost element is a child over everything else?
Like if entity A is a sibling of B, and in front of it, if I click on A, can I still trigger a click on B?
Steven — Yesterday at 3:54 PM
IIRC, it should work as long as its being rendered on top of everything else as it should get the input event first
Bogden — Yesterday at 3:55 PM
will that just happen by default? cause AFAIK it eats the input event
Yeah so like in this example project @Steven PlayCanvas 3D HTML5 Game Engine
The green overlay eats the inputs of the things behind it