SpriteRasterColourBuffer sets the sprites raster bar colour replacement buffer. The raster colour replacement buffer is an array of RGB colours that are assigned to the current surfaces (like the screen) Y axis. When the sprite is drawn in this mode, rather than replacing the key colour uniformly with the replacement colour, the replacement colour is taken from each scan line in the replacement buffer array you provide. This allows you dynamically change the replacement colour each scan line down the screen.. Giving a classic raster bar effect.
FACTS:
* SpriteRasterColourBuffer is only used when the sprites drawmode is set to a 'Raster Bar colour replace' mode.
* See SpriteDrawMode for more information about sprite draw modes.
Mini Tutorial:
This example manually creates a simple image then uses this image to show how to replace the colour replace key colour with a raster bars in sprites.
; limit program to 75 frames per second or less SetFPS 75 ; Create two arrays to hold our raster ar colours Dim RasterBUffer1(1) Dim RasterBUffer2(1) ; fill both buffers with random colour bars FillArrayWithRasters(RasterBuffer1()) FillArrayWithRasters(RasterBuffer2()) ; Create image #1, of size 100x, 100y CreateImage 1,100,100 ; Tell PB to redirect all drawing to the image RenderToImage 1 ; Draw a blue circle CircleC 50,50,50,1,RGB(0,0,255) ; draw another circle so we an see it's spinning CircleC 30,30,10,1,RGB(0,255,255) ; Draw a purple circle in the middle that we'll replace real time CircleC 50,50,25,1,RGB(255,0,255) ; Get PB to Convert this image to an FX buffer PrepareFXImage 1 ; Tell PB to direct all drawing back to the screen RenderToScreen MaxSprites=30 For Spr=1 To MaxSprites ; Create Sprite #1 CreateSprite Spr ; Set This sprite to use Image #1 SpriteImage Spr,1 ; Center the Sprite handles CenterSpriteHandle Spr ; Set the Colour replace KEY COlour (the colour to filter out) ; Were setting the COlour replace filter to screen out the ; Purple colour SpriteColourReplaceKey Spr, RGB(255,0,255) ; Randomly Set each sprite to use either one of the previuosly ; create raster buffer arrays If Rnd(1) SpriteRasterColourBuffer Spr,RasterBuffer1() Else SpriteRasterColourBuffer Spr,RasterBuffer2() EndIf ; Set Sprites draw mode to Rotated + RASTer bar colour replace SpriteDrawMode Spr, 2+32768 Next Spr ; Start the Do/loop Do ; Clear the screen to a dark re colour Cls $550000 Angle#=BaseAngle# For Spr=1 To MaxSprites ; Turn the Sprite slowly TurnSprite Spr,spr*-0.25 X#=(GetScreenWidth()/2)+CosRadius(angle#,380) Y#=(GetScreenHeight()/2)+SinRadius(angle#,280) PositionSprite Spr,x#,y# Angle#=Angle#+(360.0/MaxSprites) Next ; Draw all the sprites DrawAllSprites baseangle#=WrapAngle(baseangle#,1) ; Show the user the screen Sync ;loop back to the previous DO statement Loop ; This function fills at array with randomly colour raster bar colours Function FillArrayWithRasters(Me()) Dim me(GetScreenHeight()) radius=10 y=-radius For lp=0 To 40 RasterBar(me(),RndRGB(),y,radius) y=y+(radius*2) Next EndFunction 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) /256) And $ff0000 g=(((C And $00ff00) *Scaler) /256) And $00ff00 b=(((C And $0000ff) *Scaler) /256) And $0000ff ThisRgb=r Or g Or b y=Offset-lp If y>-1 And y=<size Then me(y)=ThisRGB y=Offset+lp If y>-1 And y=<size Then me(y)=thisrgb Next EndFunction |
|
Example Source: Download This Example ; Load Bubble Media which is located two folders back from ; this path. BubbleImage=LoadNewImage("..\../Media/bubble_64x64.bmp") PrepareFXImage BUbbleImage ; Get the replace colour key from the image RenderToImage BubbleImage ReplaceColour=Point(32,32) ; Redirect rendering back to the screen RenderToScreen ; ============================== ; 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 ; 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 Colour to Replace in this sprite SpriteColourReplaceKey Spr, ReplaceColour ; Randomly set the this sprites replacement colour SpriteRasterColourBuffer Spr, RasterBuffer() Next ; limit the program to a max of 100 frames per second SetFPS 100 Do ; Clear the Screen Cls RGB(10,20,40) ; Get the Mouse Pointers Position mX=MouseX() mY=MouseY() ; Update the Sprites TurnSpeed#=1 Sprite=GetFirstSprite() While Sprite ; check if the mouse pointer is hitting this sprite If PointHitSpritePixels(mx,my,sprite,1)=false ; Turn This sprite TurnSprite Sprite,TurnSpeed# ; Set this sprites drawmode to rotated with ; Alpha COlour Addition SpriteDrawMode Sprite, 2 Else ; Set this sprites drawmode to rotated ; with Colour Replacement SpriteDrawMode Sprite, 2+32768 EndIf ; Bump The Turn Speed TurnSpeed#=TurnSpeed#+0.25 ; Get the NExt Sprite Sprite=GetNextSprite(Sprite) EndWhile ; Draw All The Sprites DrawAllSprites ; Display information Print "Move Mouse Over Sprites" ; Show the screen Sync ; Loop back to the Do statement to keep program running 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) /256) And $ff0000 g=(((C And $00ff00) *Scaler) /256) And $00ff00 b=(((C And $0000ff) *Scaler) /256) And $0000ff ThisRgb=r Or g Or b y=Offset-lp If y>-1 And y<size Then me(y)=ThisRGB y=Offset+lp If y>-1 And y<size Then me(y)=thisrgb Next EndFunction |
|