' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' This method draws the sprite. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Method Draw() Local A# ' BC = BC * 1-Alpha ' BC = BC + Alpha*(SpriteR*(1-FogAlpha) + FogR*FogAlpha) ' OR ' BC = BC + Alpha*SpriteR*(1-FogAlpha) + Alpha*FogR*FogAlpha ' IE: ' 1. Set the sprite's alpha to Alpha*(1-FogAlpha) ' 2. Multiply the color of the fog sprite by Alpha and FogAlpha, and then add blend that over the result of the first operation. ' If the sprite has an image... If _Image <> Null ' If the sprite is not hidden, and none of its parents are hidden... If Hidden(True) = False ' Store the current visual properties so we can reset them when we are done. RenderState.Push() ' Set color, alpha, rotation, blending mode, etc. A# = 1.0-Fog(True) .SetAlpha(Alpha#(True)) .SetBlend(_Blend) .SetColor(R#(True)*A#, G#(True)*A#, B#(True)*A#) .SetRotation(Rotation#(True)) .SetScale(ScaleX#(True), ScaleY#(True)) .SetViewport(ViewportX#(True), ViewportY#(True), ViewportWidth#(True), ViewportHeight#(True)) ' If the sprite has a shadow, draw it. If (Alpha#(True) * _ShadowAlpha#) > 0 RenderState.Push() .SetAlpha(Alpha#(True) * _ShadowAlpha#) .SetColor(0, 0, 0) ' Transform shadow vector into global space, and draw shadow relative to sprite's global position. TFormVector(_ShadowVx#, _ShadowVy#, Parent(), Null) DrawImage(_Image, X#(True)+Sprite.TFormedX#(), Y#(True)+Sprite.TFormedY#(), Frame#(True)) RenderState.Pop() EndIf ' Draw sprite. DrawImage(_Image, X#(True), Y#(True), Frame#(True)) ' If the sprite's color is over 255, make it "glow" by drawing a second copy at the same location with add blend. If (R#(True) > 255) Or (G#(True) > 255) Or (B#(True) > 255) .SetColor(R#(True)-255, G#(True)-255, B#(True)-255) .SetBlend(LIGHTBLEND) DrawImage(_Image, X#(True), Y#(True), Frame#(True)) EndIf ' If the sprite's fog is greater than 0, fog the sprite by drawing a second solid-color copy at the same location with alpha blend. If Fog#(True) > 0 EnableSolidColor() A# = Alpha#(True)*Fog#(True) .SetAlpha(1.0) .SetColor(FogR#(True)*A#, FogG#(True)*A#, FogB#(True)*A#) .SetBlend(LIGHTBLEND) DrawImage(_Image, X#(True), Y#(True), Frame#(True)) DisableSolidColor() EndIf ' Restore visual properties. RenderState.Pop() EndIf EndIf End Method
EnableSolidColor() makes the sprite render using alpha, but the sprite's color rather than the color*texture color. So the sprite will be say, a solid blue siloughette instead of a normal sprite with texture colors multiplied by the sprite color.