Jump to content

Scratching Effect(mask)


Recommended Posts

Right now I'm trying to create a mask effect where once you click on a ticket that part gets erased. 

var ticketBackground = this.add.image(....)
var ticketForeground = this.add.image(....)
var ticketResult = this.add.image(...)

var shape= this.make.graphics();
var mask= shape.createGeometryMask();



//x,y are positions of the user's mouse
            x - coinWidth / 2,
            y - coinWidth / 2 ,

So I'm creating a bunch of rectangles to reveal the erased parts, but it gets really laggy when I try to play the game on android. It's fine on pc however. 

What I'm wondering is whether there is a better way to do this.

Here is the game https://condescending-euclid-58185d.netlify.com/

Link to comment
Share on other sites

Keep in mind that Graphics objects are redrawn every frame. You don't see it directly but rendering a masked object requires rendering its mask, too. The code snippet you've posted doesn't make it immediately obvious how often you add new circles, but it's probably quite often if you're doing in an input event handler. This is likely the cause for the lag since you'll quickly reach hundreds of circles.

The solution prob proposed uses a Render Texture instead of a Graphics object. Render Textures aren't cleared unless you do it yourself, so it should be quite a bit more efficient. The code in that post uses a Bitmap Mask, which is only available on WebGL, but you might still be able to use a normal Geometry Mask. I can't check the code for you right now, but I can't recall anything which would require a Graphics object.

Link to comment
Share on other sites

Thanks for the answer guys. I tried the solution but the issue is still there. I noticed that the ticketbackground image, ticketforeground image and ticketResult image kept flickering while on android chrome, but not on pc nor ios safari. Can anyone take a look at the game on android for me? It was especially bad when you select the 4 tickets option.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...