SpriteMaskColourCompression
SpriteMaskColourCompression ThisSprite, Mode
 
Parameters:

    ThisSprite = The sprite you wish to change the mask colour compression mode on
    Mode = The sprites maskcolour compression mode (0= OFF, 1= ON)
Returns: NONE
 

      SpriteMaskColourCompression lets us change the MaskColour compression mode of this sprite.


What is MaskColour Compression ?

      Maskcolour compression is a special mode in which the sprite rendering engine uses to temporally pre-compress the sprites transformed(rotated/scaled) image. Once the image is in this temporally compressed state, we can then apply effects such tint or gouraud etc etc to the pixels without them altering the mask colour. What this does is it helps the render engine remove any redundant strips of pixels prior to applying effects. Adding effects can be pretty expressive, so we want to make sure we're not drawing anything that isn't going to be visible.

      Since MaskCOlour compression is ON(1) by default, seeing it's effect is difficult to see. However if you turn the Sprites transparent flag to off, then apply an effect such as SpriteTint to our sprite, you should see that the tinting only effects the pixels that are not MaskColour. If we turn mask colour compression off, then the tint will effect all the pixels in the sprite regardless.



Possible Usage

      If you wondering why this is useful, then imagine you have a image with a mask colour $00ff00ff. Lets say you're clever an decide that rather than rotate or colour this image every frame you're going to buffer it into an animation. Reducing it's cost at run time. So your program outputs the buffered version, rather than bothering transform and apply effects to the source constantly. Which is a complete waste of time if you think about it.

      Now if you render the source image to a cache (another image), then we have to preserve the mask colour. This means clearing the cache image with the mask colour first then drawing the transparent version over it. This means the cost per pixel is potentially *2 due to the clear + render pass. However, with the compressed solid filler, the clear pass may not be necessary (assuming the source is big enough to fill the destination) Since the mask colour is preserved during the render and only 'solid' are processed.






FACTS:


     * SpriteMaskColourCompression is ON(1) by default.

     * When SpriteMaskColourCompression is ON, the MaskColour in the sprites image will not be altered by preposting sprite draw modes, such as Tint, AlphaAdd,AlphaMult, Gouraud, even when SpriteTransparent is set to OFF. Disable SpriteMaskColourCompression if that's that you want.



 
Example Source: Download This Example
; Load Bubble Media which is located two folders back from
; this path.
  BubbleImage=LoadNewFxImage("..\../Media/bubble_64x64.bmp")
  
  
; change this images mask colour
  Cls RGB(255,0,255)
  DrawImage BubbleImage,0,0,true
  GetImage BubbleImage,0,0,64,64
  RGBMaskImage BubbleImage,$00ffffff
  ImageMaskColour BubbleImage,RGB(255,00,255)
  
  
  xpos=400
  Ypos=100
  
  MAkeMySprite(xpos,Ypos,BubbleIMage,true,true)
  
  Ypos=ypos+150
  MAkeMySprite(xpos,Ypos,BubbleIMage,true,false)
  
  Ypos=ypos+150
  MAkeMySprite(xpos,Ypos,BubbleIMage,false,true)
  
  Ypos=ypos+150
  MAkeMySprite(xpos,Ypos,BubbleIMage,false,false)
  
  
  
; limit the program to a max of around 60 frames per second
  SetFPS 60.7
  
  
  Do
     
     Cls RGB(255,0,0)
     
     
   ; Turn the sprites
     Sprite=GetFirstSprite()
     While Sprite
        
        x=GetSpriteX(Sprite)
        y=GetSpriteY(Sprite)+5
        
      ; Turn This sprite
        TurnSprite Sprite,0.5
        
      ; draw this sprite now
        DrawSprite Sprite
        
        mode=GetSpriteTransparent(Sprite)
        mode=mode+(GetSpriteMaskColourCompression(Sprite)*2)
        
        Select Mode
            Case 0
                t$="Solid / No Compression"
            Case 1
                t$="Transparent / No Compression"
            Case 2
                t$="Solid / Mask Colour Compression"
            Case 3
                t$="Transparent / Mask Colour Compression"
        EndSelect
        
        CenterText x,y,T$
        
      ; Get the NExt Sprite
        Sprite=GetNextSprite(Sprite)
     EndWhile
     
     
     
   ; Show the screen
     Sync
     
   ; Loop back to the Do statement to keep program running
  Loop
  
  
  
Function MAkeMySprite(Xpos,Ypos,ThisIMage,COmpression,Transparent)
  
; Create the Sprite
  Spr=NewSprite(Xpos,ypos,ThisImage)
  
; Center this sprites handle
  CenterSpriteHandle Spr
  
; Colour the Sprite
  SpriteTint Spr,$ff0000
  
; set the Mask colour compression state
  SpriteMaskColourCompression Spr,COmpression
  
  
; set should be drawn transparent (remove mask colour) or not
  SpriteTransparent Spr,Transparent
  
  SpriteFilter spr,1
  
;     scalesprite spr,10
; Set The sprite to Rotated draw mode
  SpriteDrawMode Spr, 2
  
EndFunction Sp
 
Related Info: SpriteDrawMode | SpriteTransparent :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com