you can't on the fly...or it'll be too slow...
the fastest way to make a scanline effect is to draw all sprites with the scanline effect or precalculate it before the game start...you'll need to make the effect 2 time on all the sprites if they move by a non pair pixel number
or you're effect will be messy...
the code below add a scanline effect to a bmp picture and save 2 files with the effect.
Graphics 800,600,0,2
ScanLine_effect(RequestFile$("select a picture to apply the effect","bmp"),90,255,0,255)
;
;usage scanline_effect(filename$,percentage,transparent color r,transparent color g,transparent color b)
;
;the three parameters transparent color r
; transparent color g
; transparent color b
;
;specify a color that the scanline effect don't modify , usefull for maskimage
;
Function ScanLine_effect(file$,percentage,tr,tg,tb)
trs=tb Or (tg Shl 8) Or (tr Shl 16)
If FileType(file$)=1
temp=LoadImage(file$,2)
temp2=LoadImage(file$,2)
w=ImageWidth(temp)
h=ImageHeight(temp)
LockBuffer ImageBuffer(temp)
For y=0 To h-1
If y Mod 2=True
For x=0 To w-1
c=(ReadPixelFast(x,y,ImageBuffer(temp)) Shl 8)Shr 8
If tr<>((c Shl 8) Shr 24) Or tg<>((c Shl 16) Shr 24) Or tb<>((c Shl 24) Shr 24)
r=minmax(percent(percentage,(c Shl 8) Shr 24),0,255)
g=minmax(percent(percentage,(c Shl 16) Shr 24),0,255)
b=minmax(percent(percentage,(c Shl 24) Shr 24),0,255)
WritePixelFast(x,y,b Or (g Shl 8) Or (r Shl 16),ImageBuffer(temp))
EndIf
Next
EndIf
Next
UnlockBuffer ImageBuffer(temp)
LockBuffer ImageBuffer(temp2)
For y=0 To h-1
If y Mod 2=True
For x=0 To w-1
c=(ReadPixelFast(x,y,ImageBuffer(temp2)) Shl 8)Shr 8
If tr<>((c Shl 8) Shr 24) Or tg<>((c Shl 16) Shr 24) Or tb<>((c Shl 24) Shr 24)
r=minmax(percent(percentage,(c Shl 8) Shr 24),0,255)
g=minmax(percent(percentage,(c Shl 16) Shr 24),0,255)
b=minmax(percent(percentage,(c Shl 24) Shr 24),0,255)
WritePixelFast(x,y,b+(g Shl 8)+(r Shl 16),ImageBuffer(temp2))
EndIf
Next
EndIf
Next
UnlockBuffer ImageBuffer(temp2)
DrawBlock temp,0,0
DrawBlock temp2,0,h
SaveBuffer (ImageBuffer(temp),Left$(file$,Len(file$)-4)+"_sl1.bmp")
SaveBuffer (ImageBuffer(temp2),Left$(file$,Len(file$)-4)+"_sl2.bmp")
FreeImage temp
FreeImage temp2
Flip
WaitKey
EndIf
End Function
Function minmax(v,mn,mx)
If v<mn:v=mn:EndIf
If v>mx:v=mx:EndIf
Return v
End Function
Function percent#(per,cent)
onepercent#=(cent*1.0)/100
Return Ceil( onepercent#*per)
End Function
the best way to use them later is to have the image handles stored in an aray and test for parity to draw one or the other according to the background scanline effect
example code (not tested)
dim sprite(1)
;loading the sprite animstrips
sprite(0)=loadanimimage("mysprite_sl1.bmp",32,32,0,10)
sprite(1)=loadanimimage("mysprite_sl2.bmp",32,32,0,10)
;drawing the sprite
drawimage sprite(spritey mod 2),spritex,spritey,frame
;this draw the curent sprite frame using the good scanline effect set according to his vertical position
it's a fake scanline effect but it's the fastest way to implement it in b+ ...