Sprite Draw Modes (Real Time Colour Masking)

Started by kevin, December 20, 2005, 10:18:33 AM

Previous topic - Next topic

kevin

Just adding another 2 sprite draw modes that had been left out (for some reason)   which are ColourMask AND and ColourMask_OR.

Basically they allow you logically Mask/ effect a sprite, without effecting the original image.

 For AND you could use it split the sprites image into R,G,B planes (rotated of course!).    Might be a nice effect.

NOTE: In AND mode the logical MASK occurs before the transparent mask, so if the transparent colour is rgb(0,0,0) and you mask with Rgb(0,0,0) you'll get zero output (no pixels written).

Logical OR on the other hand is POST transparent Mask.  So it only effects pixels that weren't solid .  

Here's an example of what AND'ing can do (sorry about the screen shot, it's a little dark :) ).




; Create image from the example gfx folder.
  LoadImage "../../../../gfx/animal.jpg",1
  preparefximage 1



; Create Sprite #1
 CreateSprite 1

; Set This sprite to use Image #1
 SpriteIMage 1,1

; Center the Sprite handles
 CenterSpriteHandle 1
 
; Reset the Sprites Flash Colour (which is used as the mask colour)
 SpriteFlashColour   1, rgb(255,0,0)


; Make a copy of this sprite
 CopySprite 1,2


; Set Sprite 1's draw mode is rotated + COlourMask_AND
 SpriteDrawMode 1, 2+$10000

; Set Sprite 2 to rotated draw mode
 SpriteDrawMode 2, 2


; Calc the screen center
 sw=GetScreenWidth()/2
 sh=GetScreenHeight()/2

; position Sprite one on the left hand side
 PositionSprite 1,sw-(sw/2),sh
 
; position Sprite two on the right hand side
 PositionSprite 2,sw+(sw/2),sh





; Start the Do/loop
Do
; Clear the screen to black at the start of each update
  cls rgb(0,0,0)
 

; Display the Instructions for the user
  Print "Press Space to randomly change mask Colour)"
 
; Check if the space key is pressed
if Spacekey()=true  
  ; CHange Flash colour (which is also used as COlour mask)
  SpriteFlashColour   1, RNDRGB()
 
 endif

; Turn the Sprites slowly  (1 degree per update)
 TurnSprite 1,1
 TurnSprite 2,1

; Draw the Sprite
 DrawAllSprites
 
; Show the user the screen
Sync

;loop back to the previous DO statement, and continue the loop
loop




kevin

and here's logical AND / Normal Roated + Logical Or Mode