Kadajus Posted November 18, 2016 Share Posted November 18, 2016 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 More sharing options...
Kadajus Posted November 18, 2016 Author Share Posted November 18, 2016 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 More sharing options...
Recommended Posts