After seeing the Wii Spray demo videos a year or so ago I have since been wondering how they did the stencils. I couldn’t find any information on how to achieve an effect like paint stenciling so today I decided to give it a shot myself. Below is a small demo where you can have a go and spraying some stencils. Instructions are in the bottom left corner. Here is how it works:
Layers (top to bottom):
- Draw Layer Bitmap – contains BitmapData where the spray paint is drawn
- Stencil MovieClip – the stencil you see on screen containing artwork with transparency
- Stencil BitmapData – stencil is drawn to this bitmap data (not added to display list)
- Canvas Bitmap – where final artwork is drawn to
The process
- when stencil is moved and placed somewhere, the Stencil BitmapData is filled with red, then the Stencil MovieClip is drawn on top.
- you then paint with the mouse – paint is drawn to Draw Layer Bitmap
- on mouse up a Temporary BitmapData is created
- it then loops through all pixels in Stencil BitmapData – if pixel is Red: copy corresponding pixel from Draw Layer Bitmap to Temporary BitmapData
- when the loop is complete draw the Temporary BitmapData to the Canvas BitmapData
- Draw Layer Bitmap is then cleared