Skip to main content
August 6, 2013
Question

Bitmap, blitting and masks

  • August 6, 2013
  • 1 reply
  • 718 views

I have a 2d isometric game map that is blitted into a single Bitmap. I also then have a character MovieClip animation on top that can walk around the screen.

In certain areas there are things (walls etc) on the game map that must appear above the character, not beneath. To achieve this, I have a transparent bitmap covering the character and when an object needs to appear above the character I add that object's bitmapData to this bitmap. Whenever the character moves the bitmap is cleared and redrawn. For example, my display order could be: gameMap > character > a wall piece .

My problem occurs when the user goes behind an element with transparency. I end up drawing the transparent element ontop of the copy in the game map, which makes the element appear less transparent.

I am thinking I would like to try some sort of mask. For example, I could use the transparent bitmap above the character as a mask for the entire game map beneath and do something like 'underneath the non-transparent areas of the bitmap above the character, make all the pixels in the game map bitmap transparent/hidden'.

I have tried doing this by doing bitmapData.fillRect(rect beneath character, transparent pixel) on the gameMap underneath which works well in removing the elements, but then the gamemap must be redrawn again afterwards which causes quite the performance hit.

Any ideas? Thanks

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 6, 2013

why not make the blitted bit beneath the semi transparent element totally transparent?

August 6, 2013

That would work, but it doesn't look good

kglad
Community Expert
Community Expert
August 7, 2013

what about it is not perfect?