SpriteTint
SpriteTint ThisSprite, ThisRGB
 
Parameters:

    ThisSprite = The Sprite that you want to change the diffuse colouring of
    ThisRGB = The RGB colour that the sprite will be tinted with. Default is ARGB(255,255,255,255)
Returns: NONE
 

      SpriteTint sets the sprites base Tint (diffuse) colour. Changing the tint colour allows us to dynamically alter the colouring of the sprites image (See SpriteImage), without changing the image itself.

      The tint process can be quite an expensive one. Basically each pixel in the sprites are being sepreately multiplied by the Sprites Tint colour prior to being drawn. All this multiplication adds some extra overhead to the sprite. You can emulate the process yourself, by running through an image and reading each pixel colour from the image (Point), then applying RgbAlphaMULT to it, then drawing it back.

      Since the sprite images colour channels are multiplied separately, we can think of the tint colour as scalars for the separate R,G,Bs in the image. So setting the Tint colour of RGB(255,255,0), will leave the R & G channels as is, but completely remove the B channel from it. Setting Tint to RGB(128,128,128) will reduce the colours by half.

      Bellow we have some examples of how the tint values alters the output. The top left is the sprite with the default tint. In this mode the rendering engine just draws the image as is. Then we're applying various tint values to the rest of sprites.





FACTS:


      * Sprites default tint colour is ARGB(255,255,255,255) (white).

      * When a tinted sprite is drawn, the sprites image pixels are each multiplied by the tint colour. This can impact really render performance on big sprites, so it's best used sparingly.

      * See SpriteDrawMode for more effects that can be combined with sprite tint.

      * Tint and be used with control the ALPHA LEVEL when the sprites using an AFX formatted image.





Mini Tutorial:



 
Example Source: Download This Example
; Load Bubble Media which is located two folders back from
; this path.
  
  BubbleImage=LoadNewFxImage("..\../Media/bubble_64x64.bmp")
  
  
; Create a number of ranomdly positioned sprites
  For lp=1 To 25
     
   ; Get a random coord on the screen
     X=Rnd(GetScreenWidth())
     Y=Rnd(GetScreenHeight())
     
   ; Create a sprite
     Spr=NewSprite(X,y,BubbleImage)
     
   ; Center this sprites handle
     CenterSpriteHandle Spr
     
   ; Set this sprites drawmode to plain rotated
     SpriteDrawMode Spr, 2
     
     // Set this sprites tint colour to some random value
     SpriteTint Spr,RndRGB()
     
  Next
  
  
; limit the program to a max of 75 frames per second
  SetFPS 75
  
  
  
  Do
   ; Clear the Screen
     Cls RGB(30,40,70)
     
     
   ; Update the Sprites
     TurnSpeed#=1
     
     Sprite=GetFirstSprite()
     While Sprite
      ; Turn This sprite
        TurnSprite Sprite,TurnSpeed#
        
      ; Bump The Turn Speed
        TurnSpeed#=TurnSpeed#+0.25
        
      ; Get the NExt Sprite
        Sprite=GetNextSprite(Sprite)
     EndWhile
     
     
   ; Draw All The Sprites
     DrawAllSprites
     
     
   ; Show the screen
     Sync
     
   ; Loop back to the Do statement to keep program running
  Loop
  
  
  
  
  
 
Related Info: GetSpriteTint | SpriteDrawMode :
 


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