Use Image with drawMask?


(Skelyton) #1

I’m trying to use an image as my mask, but drawMask wants BitmapData. I’ve tried getting the Image’s .source but it says .source doesn’t exist.

package  {
import net.flashpunk.Entity;
import flash.display.BitmapData;
import net.flashpunk.graphics.Image;
import net.flashpunk.FP;

/**
 * ...
 * @author Skelyton
 */
public class Bladder extends Entity
{		
	[Embed(source = '../assets/graphics/bladderEmpty.png')] private const BLADDEREMPTY_GRAPHIC:Class;
	[Embed(source = '../assets/graphics/bladderFill.png')] private const BLADDERFILL_GRAPHIC:Class;
	[Embed(source = '../assets/graphics/bladderMask.png')] private const BLADDERMASK_GRAPHIC:Class;
	
	protected var bladderEmptyImg:Image;
	protected var bladderFillImg:Image;
	protected var clippingMask:Image;
	//protected var clippingArea:Rectangle;
	
	public function Bladder() 
	{
		bladderEmptyImg = new Image(BLADDEREMPTY_GRAPHIC);
		bladderFillImg = new Image(BLADDERFILL_GRAPHIC);
		clippingMask = new Image(BLADDERMASK_GRAPHIC);
		graphic = bladderEmptyImg;
		//clippingMask = new BitmapData(92, 108, false, 0x00ffffff);
		
		this.x = FP.screen.width - 112;
		this.y = 20;
		
		bladderEmptyImg.drawMask = clippingMask.source;

(Jonathan Stoler) #2

Try:

bladderEmptyImg.drawMask = new BLADDERMASK_GRAPHIC().bitmapData;


(Skelyton) #3

THANK YOU SO MUCH!! I have been pillaging my way through the entire internet for a day and a half with no solutions. Thank you!


(Skelyton) #4

Now my problem is that I want to move the image down over time, but have the mask stay in place. But it seems the Mask’s coordinates are the images.


(Abel Toy) #5

Wow. There is a drawMask for Images in FlashPunk? When was this added?