Post by matty47 on Jul 12, 2024 18:03:50 GMT -6
Just some, probably trivial, code to do transitions from one image to another. First the transition code "transition.bas"
include Once
function fadeImg(imgA,imgB)
imgAlpha = 0
while imgAlpha <256
ClearCanvas
DrawImage(imgA,0,0)
SetImageAlpha(imgB,imgAlpha)
DrawImage(imgB,0,0)
update()
imgAlpha = imgAlpha+1
Wend
return 1
end Function
function slideL(imgA,imgB,speed)
x=0
dim finalX,Y
GetImageSize(imgA,finalX,Y)
while x > -finalX
ClearCanvas
DrawImage(imgA,x,0)
DrawImage(imgB,x+finalX,0)
Update()
x=x-speed
wend
return 1
end function
function slideR(imgA,imgB,speed)
x=0
dim finalX,Y
GetImageSize(imgA,finalX,Y)
while x < finalX
ClearCanvas
DrawImage(imgA,x,0)
DrawImage(imgB,x-finalX,0)
Update()
x=x+speed
wend
return 1
end function
function slideU(imgA,imgB,speed)
y=0
dim X,finalY
GetImageSize(imgA,X,finalY)
while y > -finalY
ClearCanvas
DrawImage(imgA,0,y)
DrawImage(imgB,0,y+finalY)
Update()
y= y-speed
wend
return 1
end function
function slideD(imgA,imgB,speed)
y=0
dim X,finalY
GetImageSize(imgA,X,finalY)
while y < finalY
ClearCanvas
DrawImage(imgA,0,y)
DrawImage(imgB,0,y-finalY)
Update()
y= y+speed
wend
return 1
end function
t code here
and a prog to test itInclude "transition.bas"
'open a window
mainWin = 0
WindowOpen(mainWin,"Transition Test",WINDOWPOS_CENTERED,WINDOWPOS_CENTERED,640,480,WINDOW_VISIBLE,1)
'add a canvas
canB = 1
'load our two pix
bgA = 1
bgB = 2
LoadImage(bgA,"gfx/bgA.png")
LoadImage(bgB,"gfx/bgB.png")
CanvasOpen(canB,640,480,0,0,640,480,1)
done = slideD(bgA,bgB,2)
done = slideU(bgA,bgB,2)
done = slideL(bgA,bgB,2)
done = slideR(bgA,bgB,2)
done = fadeImg(bgA,bgB)
while WindowExists(mainWin)
Update()
wend
The two images are 640x480 pix. Hope this is of some help.The speed variable was added to the slide transitions as when I increased/ decreased the values by one the transition was a bit slow. Code needs to have additional checks etc.