How to make a movable XNA mask on WP7

I have two textures: a background and a mask. I need to conclude that the mask determines what is detected in the background. The very important part is that the mask should be smaller than the size and then the background. I will move it at runtime, revealing parts of the background.

enter image description here

The project is on WP7, so there is limited BlendState manipulation.

+4
source share
1 answer

You can use the built-in AlphaTestEffect with the Stencil Buffer to achieve the disguise that you perform after.

Steps:

  • Clear stencil buffer
  • Draw your mask in the stencil buffer with AlphaTestEffect so that only opaque pixels are displayed.
  • Draw an image using masking stencil templates.

Crappy Coding article Modifying a texture using Render targets with some stencil buffer action shows how to do this and has a working code example.

+4
source

All Articles