Im missing something here, help me!
BlitzPlus Forums/BlitzPlus Programming/Im missing something here, help me!
| ||
Ive been racking my brain over this... I'm sure its really obvious but anyway.. Im re-making a classic game and I decided I wanted a scan-line effect in the game too but that would mean I would have to use transparency wouldnt it? Ive searched in this forum but none of the posts I found directly answered my question. The question is, how could I make a simple line, with a width of 640 pixels, transparent? |
| ||
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+ ... |
| ||
Thanks for your help. It works a charm. Although I couldnt see how the other method would chew up system resources. Couldnt it be possible just to apply the "scanline layer" ontop of the game? |
| ||
blitz+ don't have any builtin transparency. so you'll have to run the previous code all frames ... you can test this if you wan't to test anyway :) testpicture=LoadImage(RequestFile("choose a picture (small)")) Graphics 640,480,0,2 SetBuffer BackBuffer() Repeat DrawBlock testpicture,MouseX(),MouseY() scanline_effect(50) Flip Until KeyDown(1) Function ScanLine_effect(percentage) LockBuffer BackBuffer() For y=0 To GraphicsHeight() Step 2 For x=0 To GraphicsWidth() c=(ReadPixelFast(x,y,BackBuffer()) Shl 8)Shr 8 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)) Next Next UnlockBuffer 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 too slow :( |
| ||
Ah yeah, now I understand. Thanks for your help. |