Jump to content

Moving alphaMask


Kadajus
 Share

Recommended Posts

Hello,

I've got this issue and I'm not able to find any answers.
I have 2 images - background and a soft edged circle for a mask. Background stays in same place, but the circle should be able to move.
As far as I understand I can send mask coordinates when using alphaMask(source, mask, sourceRect, maskRect) by sending maskRect settings, but if I create rectangle (var rect2 = new Phaser.Rectangle(200, 200, 300, 300);) before applying alphaMask, the mask doesn't work. How can I send maskRect options? Or I should approach this somehow differently?

Current code I have:

var bmd = game.make.bitmapData(2141, 800);
bmd.alphaMask('BG_Dark', 'Mask');
game.add.image(0, 0, bmd);

Now it simply places both the BG and Mask at 0,0. But I need the mask to be, for example, at 300,300;

Link to comment
Share on other sites

Ok, I actually managed to solve the first problem like this:

//Create custom bitmapData containing the mask
maskD = game.make.bitmapData(2141, 800);
maskD.draw('Mask', 200, 200, 200, 200);

//Apply the mask and add it to the game	
bmd = game.make.bitmapData(2141, 800);
bmd.alphaMask('BG_Light', maskD);
game.add.image(0, 0, bmd);

 

Now the other problem is redrawing it on update... What I am doing now on each update:

maskD.clear();
maskD.draw('Mask', sprite.x - 100, sprite.y - 100, 200, 200);
bmd.clear();
bmd.alphaMask('BG_Light', maskD);
bmd.update();


It clears both the mask and the main image, and redraws it. But this is really laggy.
Can I somehow update masks position without constantly redrawing everything?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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