Pixelmask no transparency


(Danny) #1

I’m trying to create a pixelmask from the current frame on my player’s spritemap. Everything works fine except the pixelmask is just a square the size of the frame, not the shape of the actual image.

This is in the Player entity class:

   var frame:BitmapData = new BitmapData(107, 113, true, 0);
   graphic.render(frame, new Point(), new Point())
   var mask:Pixelmask = new Pixelmask(frame);
   mask.assignTo(this);

(Alex Larioza) #2

I’m not sure what your questions is, but I do have one for you - why are you using a pixel mask? It would be better to use a hitbox if all you need is a rectangular mask.


(Jacob Albano) #3

I think the meaning is that the pixelmask that is created comes out as a rectangle instead of following the shape of the image.

I have nothing in the way of advice to contribute to this because I never use Pixelmasks. :stuck_out_tongue:


(azrafe7) #4

If I get it right mask.assignTo() assigns a parent to the mask (not the other way 'round), so it would be used in cases where you want to detach a mask from an entity and assign it to another one (never had the need for that though). For actually giving a mask to an entity you just do:

this.mask = mask;

then you can use the data property on the Pixelmask to change the underlying BitmapData used as mask.

Please note that Pixelmask is expensive (memory and performance-wise), so use it sparingly and consider using a Hitbox (or a Masklist of Hitboxes) instead as @SHiLLySiT suggested.