Previous Page
Next Page

Recipe 10.13. Changing Brightness

Problem

You want to change the brightness of a display object.

Solution

Use a matrix, and apply it using a ColorMatrixFilter objects. Optionally, you can change brightness using a ConvolutionFilter object.

Discussion

You can adjust the brightness using a ColorMatrixFilter object by passing it a matrix that scales or offsets the red, green, and blue equally. The following matrix is a general representation of a matrix that scales the red, green, and blue equally:

a  0  0  0  0
0  a  0  0  0
0  0  a  0  0
0  0  0  1  0

The following matrix offsets the red, green, and blue values equally:

1  0  0  0  a
0  1  0  0  a
0  0  1  0  a
0  0  0  1  0

The following example increases the brightness of a display object by scaling the colors to twice their original values:

sampleSprite.filters = [new ColorMatrixFilter([2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0])];

You can also adjust brightness with a ConvolutionFilter object, as mentioned in Recipe 10.6.

See Also

Recipe 10.6


Previous Page
Next Page
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)