Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

[PIXIJS] [HELP] Drawing polygon inside rectangle with transparency (Hole inside rectangle)

$
0
0

Hello PIXIJS Devs.

I am working on Line of Sight in PIXIJS. So far my algo works well. I ecountered on issue, that i can not draw polygon which makes a hole inside a rectangle. 

I tried to use mask and blend modes but it did not work.

        this._lightGraphics.clear()
        beginFill(0x000000, 0.5)
        drawRect(0, 0, this.viewport.width, this.viewport.height)
        endFill()
        closePath()
        beginHole()
        drawPolygon(points)
        closePath()
        endHole()

I tried Graphics hole, it was working but not always, sometimes holes disapear for some reason.

 

Should be like this: (First image is using code above, but this is not working always) 2nd image shows there are 2 graphics (1 Rectangle which fits whole screen with black fill color and 0.5 alpha and second polygon (Vision))
image.thumb.png.72511166e1f8fbf6aa2f2fea21cd1935.png

unknown.png

I tried stacked canvas with blendMode multiply and it works. 
What is the best way to do this?

Edit: Polygon is cleared and drawn each frame. Way to make hole inside rectangle needs to be fast.


Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>