Login
Community
DARK THEME

Masking screen with polygons

I am attempting to implement a kind of lighting in a 2D game, where I define polygons of light and then use those to mask what has already been drawn on the screen, so that the entire screen is drawn black except for the portions of sprites that lie within the polygons I have defined.

Initially I thought I could do this by drawing the polygons in white on a black screen, setting the blend mode to multiply, and drawing the rest of my scene. The obvious problem is that I cannot draw any overlapping sprites the way they're intended to show, since they will multiply with each as well.

I have pretty much tried doing this in every conceivable way using different blending modes, but it never works for one reason or another, usually because the background is black instead of transparent or something like that.

Ideally, I would somehow be able to bake whole scene together and multiply that by my polygon mask (or vice versa) to get the desired outcome, but as far as I can tell, Miccrostudio is not able to do something like this right now. The only other option I can think of is taking the points of every light polygon on screen and using those to create black polygons that make up their inverse, and overlay those on the scene. I'm pretty daunted by the idea of creating an algorithm that could break that down into convex polygons, though.

Is there anything I'm missing here in terms of drawing/blending modes that would make my goal possible? It seems like it should be easier than it has turned out to be.

https://microstudio.io/i/williac0374/zombielite2/

this is something I was working on. I get 15 fps in the offline editor. I hope this helps in some way.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community