This bit comes directly from our library.
Instead of creating each needed mask manually, we found it easier to simply choose a display object, a polygon, and mask the object using the chosen polygon. We would then either run the app as is, or go into our documents directory and take the created mask so that we could use it anywhere.
If you need to mask a single image, it’s still easier to simply fill the polygon with the image itself with Graphics 2.0.
But for groups of objects, animated sprites and the likes, this made everything so much easier (;
To use it, you just need to require our library, and call the proper function, passing a display object, the polygon you wish to use as a mask, and a name for the mask that will be created.
local ragdogLib = require "ragdogLib";
local bg = display.newImageRect("image.png", 200, 200);
local polygon = display.newRect(0, 0, 100, 100); --you can use anything, from polygons to circles and rects
ragdogLib.applyMaskFromPolygon(bg, polygon, "mask1.jpg");
Get the project from here.