SpriteFilter
SpriteFilter ThisSprite, Mode
 
Parameters:

    ThisSprite = The Sprite that you want to change the filtering mode on
    Mode = Flag to set filtering mode the sprite should use (0=No filtering default, 1 = Bilinear)
Returns: NONE
 

      SpriteFilter is used to enable/disable the BiLinear sprite filtering. Sprite Filtering smoothes out the quality of rotated/scaled sprites. In particular when the sprite is scaled up. Without filtering, when a sprite is scaled up, each pixel expands, which can make the result look blocky. Filtering helps by interpolating (bleeding) neighboring pixels into each other. So the blocks become gradients in the output. You can blow the image up as far you like, but the bigger it gets the more pixels smudge together, Making it blurry.

      Also, if we scale an image down, the default scaling routines truncate the pixel it grabs without regard to the surrounding pixels. This can give some unwanted artifacts in some images, in particular images that have lots of dithered pixels, or grids/lines for example. Filtering can help reduce such effects also, since each pixels are the result of the weighted average of it's neighbors. Thus smoothing out the outputted image. It should be noted though that if you scale the image down to smaller than it's original size by more than 50%, then errors will start to be introduced.

      Here we see an example of sprite being filter when scaled at 50% intervals from 50 up to 200% of actual size.







FACTS:


      * Sprite filtering is disabled (set to 0) by default.

      * When a filtered sprite is drawn, each pixel from the sprite image is blended with it's neighboring pixels. This blending calculation is heavy (on your CPU) to perform in real time, so it's best used sparingly. Pre-calculation is recommended.

      * Sprite filtering can make images blurry the bigger they're scaled.

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


 
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: GetSpriteFilter | GetSpriteTint | SpriteDrawMode | SpriteTint :
 


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