Is it possible to create for example circular hole in rectangle element in Snapsvg? I tryed to use white and black elements and mask function but i cant figure it out. Most results was inverted (i saw only circle with color of rectangle) or no effect at all. And searching google does not helping either - only relevant thing i found was that but when i tryed to replicate it using Snapsvg it did not work so well as i tryed to describe it before (i must admit, im not fully sure if it was mine fault or its because snapsvg mask handling).
Its realy important it will be simple solution using rectangle and not something using paths or simillar things.
What im trying to achieve is simillar to gamemaker surfaces - dark foreground with hole (light) i could see background trought it.
Also im looking for solution which could handle more than one circle hole in element and dynamic position changes.
Thx for any answer, i hope it is even possible.
PS: sorry for my english, im not from english speaking country
Here you go. I've loosely recreated your image. I've made a black rectangle with a hole in it that you can see a green background through.
var s = Snap("#svg");
// Make a green rectangle. Something for us to see through the mask.
var greenbg = s.rect(0,0, 400,300);
greenbg.attr({
fill: "darkseagreen"
});
// Now create the mask.
// We want the mask to be a hole through a rectangle, so the mask
// needs to be a white (solid) rectangle with a black (hole) circle
// on top of it.
var maskrect = s.rect(0,0, 400,300); // the rect
maskrect.attr({
fill: "white"
});
var maskcircle = s.circle(140,130, 80); // the circular hole
// Now group these two items to create the combined object that becomes the mask.
spotlightmask = s.group(maskrect, maskcircle);
// Add a black foreground rectangle that we will apply the mask to.
var blackfg = s.rect(0,0, 400,300);
// Attch the mask to the black foreground rect.
blackfg.attr({
mask: spotlightmask
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg-min.js"></script>
<svg id="svg" width="500" height="500"></svg>