Hey, I am trying to recreate the game Dungeon Crawler but not in a tiled map way, but I’m having difficulties trying to mask a grid with another object which is also masked.
I have three layers:
1. Grid (Geometry)
2. Ray casting layer (Geometry, yellow coloured polygon on the first image)
3. Gradient alpha mask (Bitmap)
Right now I have this:
Layer 3’s mask is set to a GeometryMask of layer 2 -> FOV layer (As seen in the second image)
How do I use this resulting masked bitmap to mask the grid?
I think you can’t chain masks together. Maybe draw the rays (Graphics) and gradient (image) to a render texture then create a bitmap mask from the render texture.
// update mask position
this.mask.setX(this.square.x)
this.mask.setY(this.square.y)
// lightGraphics stuff
this.lightGraphics.clear()
this.lightGraphics.fillStyle(0xfff000, 1)
this.lightGraphics.beginPath()
// this.lightGraphics.moveTo()
// this.lightGraphics.lineTo()
this.lightGraphics.closePath()
this.lightGraphics.fillPath()
// clear RT and draw mask
this.rt.clear()
this.rt.draw(this.mask) // <<< this draws the image, not the masked result
I was thinking the render texture should be the only mask in the scene, but now I see that you still have to clip the gradient somehow when drawing it to the render texture.
With the Canvas renderer, you can do this with blend modes SOURCE_IN or DESTINATION_IN.
With WebGL, there is erase() but I think you would have to invert the gradient to erase with it.
Thanks samme! I ended up drawing the inverse of of light polygon in another render texture, and drawing that into the existing render texture so that it covers up the remaining white spaces of the masked rays. (Instead of inverting the gradient)