Jump to content

Scale an image and apply a mask to it


Recommended Posts



I'm working on a web app that receives jpg images from the server, and I need to resize the received image to the size of a mask .png image.

I'm trying as follows, but I don't find the way to scale the image that I get from the cache.

Can anyone help me? Thanks,


// get the size of the mask .png image here

var maskImage = game.cache.getImage('mainMask');

// make a bitmapData with that size

var bmd = game.make.bitmapData(maskImage.width, maskImage.height);


// get the image received from the server  that must be masked

var currImage = game.cache.getImage(cacheKey);


// ======>>>>>>> scale / resize / crop the currImage here to match the mask image size, and put the result into the cache


// apply mask

bmd.alphaMask(cacheKey, 'mainMask');


// create the sprite

var sprite = game.add.sprite(game.rnd.integerInRange(maskImage.width / 2, 1000), game.rnd.integerInRange(maskImage.height / 2, 1000), bmd);

Link to comment
Share on other sites


  • Recently Browsing   0 members

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