SpriteDrawMode
SpriteDrawMode SpriteIndex, DrawMode
 
Parameters:

    SpriteIndex = The identifier of the sprite you wish to alter of the Draw Mode of
    DrawMode = The Draw Modes flag for this sprite
Returns: NONE
 

      SpriteDrawMode sets the sprites draw mode property. This effects how PlayBASIC will render this sprite. You have a number different effects modes to choose from. Moreover most effects can be combined with Rotation, Scaling, Tinting, Filtering and Alpha Channels also.



Available Draw Mode Values

00 = BlitMode. (Default Mode)
01 = Expansion
02 = RotationMode.
04 = AlphaMode. (Variable Alpha Blends the sprite image)
08 = AlphaBlend 50/50
16 = Alpha Addition
32 = Alpha Subtraction
64 = Fade
128 = Gouraud Fade
256 = RGB Gouraud 50/50 Alpha Blend
512 = RGB Gouraud Alpha Addition
1024 = Colour Flash
2048 = Colour Alpha (variable cross fade sprite with colour)
4096 = Colour Alpha ADD
8192 = Colour Alpha SUB
16384 = Colour Replace
32768 = Raster Bar Colour Replace
65536 = Colour Mask Bitwise AND
131072 = Colour Mask Bitwise OR


      Note: We highly recommended you read the Images tutorials




BlitMode FACTS:

      * Sprite Image is drawn as is. Rotation, Scaling have no affect upon the image.




Rotation Mode FACTS:

      * By default rotation occurs around the images top left hand corner (0x,0y). If you want it to be centered use the SpriteHandle, CenterSpriteHandle or AutoCenterSpriteHandle commands

      * Rotation mode also activates sprite scaling. Use the ScaleSprite,ScaleSpriteXY etc controls the size.

      * Alpha Mode requires the sprites image to be stored either FX or AFX format. PrepareFXImage, LoadFxImage, NewFxIMage







Alpha Mode FACTS:

      * Variable Alpha Blends between then source image and the current drawing surface. Use the SpriteAlphaLevel command to control the blending level.

      * When SpriteAlphaLevel is set to the zero, then sprite is not drawn at all.

      * When SpriteAlphaLevel is set to the one or above, then sprite is not drawn using alpha, but BlitMode for better speed.

      * Alpha Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Alpha Blending directly to video memory can be a very slow process. It should be used sparingly!







Alpha Blend 50/50 FACTS:

      * Alpha Blend the source image and the current drawing surface. The two are merged with an equal amount of each. It's the same as using Alpha Blend mode above with a blend level of 0.5, except this version is faster.

      * Alpha Mode requires the sprites image to be stored either FX or AFX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Alpha Blending directly to video memory can be a very slow process. It should be used sparingly








Alpha Addition FACTS:

      * Alpha Addition take each pixel in the source image and adds them with the backdrop.

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Alpha Blending directly to video memory can be a very slow process. It should be used sparingly

      * Only works in conjunction with rotated mode.









Alpha Subtraction FACTS:

      * Alpha Subtraction take each pixel in the source image and subtracts them with the backdrop.

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Alpha Blending directly to video memory can be a very slow process. It should be used sparingly

      * Only works in conjunction with rotated mode.










Fade FACTS:

      * Fade allows each pixel in the sprite to uniformly faded before rendering. The level can be controlled using the SpriteFadeLevel command

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Only works in conjunction with rotated mode.









Gouraud Fade FACTS:

      * Gouraud Fade allows each pixel in the sprite to faded before rendering. The fade level of each pixel is determined via gouraud shading the sprite vertex colour levels. The vertex colours of each corner of the sprite can be set using the SpriteImageRGB command. The new colour is computed by Multiplying the Gouraud pixel with the image pixels.

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Only works in conjunction with rotated mode.












RGB Gouraud 50/50 Alpha Blend FACTS:

      * RGB Gouraud 50/50 Blend, alpha blends each pixel in the sprites image with a gouraud shaded RGB value. The pixels are merged together before rendering You can control the gouraud RGB values at each corner (vertex) on the sprite using the SpriteImageRGB command

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Only works in conjunction with rotated mode.








RGB Gouraud Alpha ADD FACTS:

      * RGB Gouraud Alpha Add, adds each pixel in the sprites image with a corresponding gouraud shaded RGB value. The pixels are merged together before rendering You can control the gouraud RGB values at each corner (vertex) on the sprite using the SpriteImageRGB command

      * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

      * Only works in conjunction with rotated mode.










Colour Flash FACTS:

     * Colour Flash will replace all none transparent pixels in the sprite with the flash colour. You can set the flash colour using the SpriteFlashColour command

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.








Colour Alpha FACTS:

     * Colour Alpha allows you to apply a variable alpha blend between the sprites pixels and set colour. The blend colour is set using the SpriteAlphaColour command and level of blending is controlled using the SpriteAlphaLevel command

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.







Colour Add FACTS:

     * Colour Add mode performs a fixed alpha addition between colour value to the sprites pixels before drawing. The blend colour is set using the SpriteAlphaAddColour command.

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.









Colour Sub FACTS:

     * Colour Sub mode performs a fixed alpha subtraction between the sprites alpha subtraction colour value and all sprites pixels before drawing.

      The subtraction colour is set using the SpriteAlphaSubColour command.

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.









Colour Replace FACTS:

     * Colour Replace mode will replace a user defined colour in the sprites image with a alternative colour while drawing. The alternative colour is set using the SpriteReplacementColour command and the colour key is set using the SpriteColourReplaceKey command.

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.





Raster Bar Colour Replace FACTS:

     * Raster Bar Colour Replace mode will replace a user defined colour in the sprites image with a alternative colour from a colour buffer before drawing. The colour buffer is applied to the y axis of the screen as the sprite is rendered. So each horizontal scan line (raster) can have an alternative replacement colour. This lets you run raster bars through sprites dynamically. You can set the colour buffer array using the SpriteRasterColourBuffer command and the colour key is set using the SpriteColourReplaceKey command.

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.





Colour Mask Logical AND - FACTS

     * Colour Mask Logical AND mode will perform a logical AND operation between the sprites ColourFlash colour and all pixels in the sprite. You can set the flash colour using the SpriteFlashColour command

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.







Colour Mask Logical OR - FACTS

     * Colour Mask Logical OR mode will perform a logical OR operation between the sprites ColourFlash colour and all none transparent pixels in the sprite. You can set the flash colour using the SpriteFlashColour command

     * This Mode requires the sprites image to be stored in FX format. PrepareFXImage, LoadFxImage, NewFxIMage

     * Only works in conjunction with rotated mode.


 
Example Source: Download This Example
; convert default font #1 from a true type font
; to a bitmap version
  MakeBitmapFont 1,$ffffff
  
; load the bubble image  and Prepare this image for
; Effects (rotation in this case)
  LoadFxImage CurrentDir$()+"..\../Media/bubble_64x64.bmp",1
  
; get the Screen widht/height
  sw=GetScreenWidth()
  sh=GetScreenHeight()
  
  
  BackDropImg=NewFXImage(sw,sh)
  
  
  iw=GetImageWidth(1)
  ih=GetImageHeight(1)
  
  
; ==================================================================
; Manually Create Some Sprites, each with different DRAW MODES..
; ==================================================================
  
  Spr=1
  
; ==============================
; NORMAL ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; ALPHA ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+4
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; ALPHA 50/50 ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+8
  CenterSpriteHandle spr
  Inc spr
  
; ==============================
; ALPHA ADD ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+16
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; ALPHA SUB ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+32
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; SHADE ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+64
  SpriteFadeLevel Spr,0.5
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; Gouraud SHADE ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+128
  CenterSpriteHandle spr
;   SpriteImageIntensity Spr,0,255
;  SpriteImageIntensity Spr,1,255
;  SpriteImageIntensity Spr,2,105
; SpriteImageIntensity Spr,3,5
  SpriteImageRGB Spr,0,RGB(255,255,255)
  SpriteImageRGB Spr,1,RGB(255,255,255)
  SpriteImageRGB Spr,2,RGB(105,105,105)
  SpriteImageRGB Spr,3,RGB(5,5,5)
  
  Inc spr
  
  
  
; ==============================
; Gouraud SHADE 50/50 BLend ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+256
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; Gouraud SHADE ADDition ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+512
  CenterSpriteHandle spr
  Inc spr
  
  
  
; ==============================
; Colour Flash ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteFlashColour Spr,$ff0000
  SpriteImage Spr,1
  SpriteDrawMode spr,2+1024
  CenterSpriteHandle spr
  Inc spr
  
  
; ==============================
; Alpha Colour ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+2048
  SpriteAlphaColour Spr,$ffff00
  CenterSpriteHandle spr
  Inc spr
  
; ==============================
; Alpha Colour ADD  ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+4096
  SpriteAlphaAddColour Spr,$ff0000
  CenterSpriteHandle spr
  Inc spr
  
; ==============================
; Alpha Colour SUB ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+8192
  SpriteAlphaSubColour Spr,$00ff00
  CenterSpriteHandle spr
  Inc spr
  
  
  
; ==============================
; Single Colour Replacement in ROTATED SPRITE
; ==============================
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+$4000
  SpriteTransparent spr,off
  SpriteColourReplaceKey Spr,$000000
  SpriteReplacementColour Spr,$00ff00
  CenterSpriteHandle spr
  Inc spr
  
  
  
  
; ==============================
; Raster Bar Colour Replacement in ROTATED SPRITE
; ==============================
  
  Dim RasterBuffer(GetScreenHeight())
  
  y=0
  radius=16
  For lp=0 To 20
     RasterBar(RasterBuffer(),RndRGB(),y,radius)
     y=y+(radius*2)
  Next
  
  
  
  CreateSprite Spr
  SpriteImage Spr,1
  SpriteDrawMode spr,2+$8000
  SpriteTransparent spr,off
  SpriteColourReplaceKey Spr,$000000
  SpriteRasterColourBuffer Spr,RasterBuffer()
  
  CenterSpriteHandle spr
  Inc spr
  
  
  
  Numb_Of_Sprites=Spr
  
  
; Run through and posiiton the sprites across
; and down the screen
  
  boarder=60
  y=boarder
  X=boarder
  For Spr=1 To  Numb_of_Sprites-1
     PositionSprite spr,X,y
     X=x+(iw+(iw))
     If X>(Sw-boarder)
        x=boarder
        y=y+(ih+(ih))
     EndIf
  Next
  
  
  
  
; Start of DO/Loop
  
  
  Do
     
     
     RenderToImage BackDropImg
     
     
     LockBuffer
     scrollX=Mod((scrollX+1),iw)
     scrollY=Mod((scrollY+1),ih)
     
     TileImage 1,ScrollX,ScrollY,0
     
     r=400
     ox=CosRadius(angle#,r/8)
     oy=SinRadius(angle#,r/8)
     c=$8faa00
     
     InkMode 1+64
     
     CircleC ox+(sw/2)+r,oy+(sh/2)+r,r,1,c
     CircleC ox+(sw/2)-r,oy+(sh/2)+r,r,1,c
     CircleC ox+(sw/2)+r,oy+(sh/2)-r,r,1,c
     CircleC ox+(sw/2)-r,oy+(sh/2)-r,r,1,c
     
     
     
     // =================================================
     // Run Through and update all the sprites positions
     // =================================================
     For Spr=1 To  Numb_of_Sprites-1
        RotateSprite Spr,Angle#
        SpriteAlphaLevel Spr,0.5+(Cos(angle#)*0.4)
        SpriteFadeLevel Spr,0.5+(Cos(angle#)*0.4)
        ScaleSprite Spr,1.5
        DrawSprite spr
     Next spr
     
     UnLockBuffer
     
     If RightKey()  Then Angle#=WrapAngle(angle#,3)
     If LeftKey()  Then Angle#=WrapAngle(angle#,-3)
     
     angle#=WrapAngle(angle#,4.5)
     
     RenderToScreen
     DrawImage backdropimg,0,0,0
     
     Text 0,0,FPS()
     Sync
  Loop
  
  
  
  
  
Function RasterBar(Me(),C,Offset,radius)
  AngleStep#=90.0/Radius
  Size=GetArrayElements(me(),1)
  For lp =0 To radius
     Scaler=Cos(lp*anglestep#)*255
     r=(((C And $ff0000*Scaler) /256And $ff0000
     g=(((C And $00ff00*Scaler) /256And $00ff00
     b=(((C And $0000ff*Scaler) /256And $0000ff
     ThisRgb=Or g Or b
     y=Offset-lp
     If y>-1 And y=<size
        me(y)=ThisRGB
     EndIf
     y=Offset+lp
     If y>-1 And y=<size
        me(y)=thisrgb
     EndIf
  Next
EndFunction
  
  
  
  
  
 
Related Info: DrawAllSprites | DrawOrderedSprites | DrawSprite | GetSpriteAlphaLevel | GetSpriteDrawMode | Images | PrepareFXImage | SpriteAlphaAddColour | SpriteAlphaColour | SpriteAlphaLevel | SpriteAlphaSubColour | SpriteColourReplaceKey | SpriteFadeLevel | SpriteFlashColour | SpriteHandle | SpriteImage | SpriteImageIntensity | SpriteImageRGB | SpriteImageUV | SpriteRasterColourBuffer | SpriteReplacementColour :
 


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