Does anyone have a code example of creating a motion blur overlay effect?
Thanks
Thanks
SuperStrict Graphics 1024,768 Local backgroundimg:Timage=LoadImage("j:\monkey4.jpg") Local spriteimg:Timage=LoadImage("C:\Code\BlitzMax\samples\digesteroids\graphics\Digestive.png") Global oldcoord:Int[5,2] ' Array with 5 slots to remember old positions. [n,0]=X, [n,1]=Y Local t:Int ' Temporary counter variable Local Average:Int ' Whether or not we want to smooth the movements. For t=0 To 4 'We have an array of 5 positions (0 through 4) which hold the previous locations of the sprite 'that we want to follow. first pre-populate all slots to the beginning position of the sprite, 'so that we start out with no trail. using mousex and mousey since those are the sprite position. oldcoord[t,0]=MouseX() oldcoord[t,1]=MouseY() Next SetBlend alphablend DrawImage(backgroundimg:Timage,0,0) While Not KeyDown(key_escape) For t=3 To 0 Step -1 ' Move the old positions each one spot down the line in the array, overwriting the last spot oldcoord[t+1,0]=oldcoord[t,0] oldcoord[t+1,1]=oldcoord[t,1] Next oldcoord[0,0]=MouseX() ' and store the current position at the first slot oldcoord[0,1]=MouseY() SetAlpha 1.0 ' Set the alpha to full DrawImage(backgroundimg:timage,0,0) ' draw the current background image SetAlpha 0.2 ' Set the alpha to 0.2 for the final, weakest copy in the trail, and draw at the ' oldest remembered coordinates DrawImage(spriteimg:timage,oldcoord[4,0],oldcoord[4,1]) If average=True Then ' If average is enabled, then draw an intermediate fade on the location SetAlpha 0.3 ' in between the oldest and second-oldest locations DrawImage(spriteimg:timage,(oldcoord[4,0]+oldcoord[3,0])/2,(oldcoord[4,1]+oldcoord[3,1])/2) End If SetAlpha 0.4 ' draw a stronger copy on the next position in line DrawImage(spriteimg:timage,oldcoord[3,0],oldcoord[3,1]) If average=True Then ' ETC. SetAlpha 0.5 DrawImage(spriteimg:timage,(oldcoord[3,0]+oldcoord[2,0])/2,(oldcoord[3,1]+oldcoord[2,1])/2) End If SetAlpha 0.6 DrawImage(spriteimg:timage,oldcoord[2,0],oldcoord[2,1]) If average=True Then SetAlpha 0.7 DrawImage(spriteimg:timage,(oldcoord[2,0]+oldcoord[1,0])/2,(oldcoord[2,1]+oldcoord[1,1])/2) End If SetAlpha 0.8 DrawImage(spriteimg:timage,oldcoord[1,0],oldcoord[1,1]) If average=True Then SetAlpha 0.9 DrawImage(spriteimg:timage,(oldcoord[1,0]+oldcoord[0,0])/2,(oldcoord[1,1]+oldcoord[0,1])/2) End If SetAlpha 1.0 ' Set the alpha to full again and draw the DrawImage(spriteimg:timage,oldcoord[0,0],oldcoord[0,1]) ' active sprite on top of the faded trail Flip ' Show everything If MouseDown(1) Then average=True ' Draw the averaged intermediate fades when the left mousebutton is held Else average=False ' Or don't draw them if the left mouse button is not pressed End If Wend
createimage(background:TImage,graphicswidth(), graphicsheight()) ' Create an image to hold the current screen in setclscolor (0,0,0) while not keydown(key_escape) cls SetAlpha 0.8 DrawImage (background:Timage,0,0) SetAlpha 1.0 Drawimage MySprite,mousex(),mousey()' draw all your real current images now, and do the rest of your stuff ' GrabImage(background:Timage,0,0) ' Store a copy of the current screen in its final state, so we can redraw it later at a lower alpha flip wend