News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Draw Cross Faded Image

Started by kevin, September 15, 2010, 08:19:43 AM

Previous topic - Next topic

kevin

  Draw Cross Faded Image

   This function shows a way we can draw an image with a variable cross fade between a pair of images.    So to test this you'll need to tell it the location of the two pictures on your computer.


PlayBASIC Code: [Select]
   Path$="LOCATION OF THE PICTURES ON YOUR COMPUTER"

Width=200
Height=170
Dim BLock(2)

BLock(0)=NewfxImage(width,Height)
Block(1)=LoadNewFxImage(path$+"Picture1.bmp")
Block(2)=LoadNewFxImage(path$+"Picture2.bmp")

; scale them to be the same size
ScaleIMage Block(1),Width,Height,1+2
ScaleIMage Block(2),Width,Height,1+2

Do
Cls 0

Angle#=wrapangle(Angle#,1)
scale#=0.5+cos(angle#)*0.5

DrawCrossFadedImage(0,100,100,false)
DrawCrossFadedImage(1,400,100,false)
DrawCrossFadedImage(scale#,100,300,false)

print fps()
Sync
loop



Function DrawCrossFadedImage(Scale#,XPos,Ypos,transparent)
Scale#=cliprange#(Scale#,0,1)
if Scale#<=0.01
ThisImage=Block(1)
elseif Scale#>=0.99
ThisImage=Block(2)
else
ThisImage=Block(0)
oldsurface=getsurface()
RendertoImage ThisImage
DrawIMage Block(1),0,0,false
DrawAlphaIMage Block(2),0,0,Scale#,false
rendertoimage OldSurface
endif
Drawimage ThisImage,Xpos,ypos,transparent
EndFunction