Pour tester vous aurez besoin de 3 images
nommez cette image fond11.jpg

nommez cette image fond22.jpg

et enfin vous aurez besoin d'une troisième image qui sera le masque utilisé pour la transition,
Récupérez 019-Whorl01.png

Et vous pouvez lancer le code avec les 3 images dans le même répertoire.
Il faut utiliser le sous système directX9.
Code : Tout sélectionner
;Comtois le 12/07/2009
ExamineDesktops()
InitSprite()
InitKeyboard()
OpenScreen(640,480,32,"Fondue")
UseJPEGImageDecoder()
UsePNGImageDecoder()
Structure s_pixel
P1.c
P2.c
P3.c
P4.c
EndStructure
Enumeration
#SpriteA
#SpriteB
#SpriteC
#SpriteT
EndEnumeration
LoadSprite(#SpriteA,"fond11.jpg")
LoadSprite(#SpriteB,"fond22.jpg")
CreateSprite(#spriteC,SpriteWidth(#SpriteA),SpriteHeight(#SpriteA))
Procedure Transparence1(transition.s, trans)
;Principe
;Le sprite C = le résultat de la fondue entre le sprite A et le Sprite B
;Valeur exacte
;CouleurC = (alphaB * couleurB + (((255 - alphaB) alphaA * CouleurA)/255))/255
;Plus rapide mais moins exacte
;CouleurC = (alphaB * couleurB + (((255 - alphaB) alphaA * CouleurA)>>8)) >>8
LoadSprite(#SpriteT,transition)
StartDrawing(SpriteOutput(#spriteA))
*PtrA.s_pixel=DrawingBuffer()
Pitch=DrawingBufferPitch()
StopDrawing()
StartDrawing(SpriteOutput(#spriteB))
*PtrB.s_pixel=DrawingBuffer()
Pitch1=DrawingBufferPitch()
StopDrawing()
StartDrawing(SpriteOutput(#spriteC))
*PtrC.s_pixel=DrawingBuffer()
StopDrawing()
StartDrawing(SpriteOutput(#spriteT))
*PtrT.s_pixel=DrawingBuffer()
StopDrawing()
If *PtrA=0 Or *PtrB=0 Or *PtrC=0 Or *PtrT = 0
End
EndIf
;AlphaA=255-trans ; Pour une fondue entre deux images
;AlphaB=trans
pos = 0
Fin = SpriteWidth(#SpriteA)+SpriteHeight(#SpriteA)*pitch
While pos <= Fin
Temp=*PtrT\P1+trans
If Temp>255
Temp=255
ElseIf Temp<0
Temp=0
EndIf
AlphaA=255-Temp ;(dans cette procédure le niveau de transparence est issu d'une 3ème image - transition)
AlphaB=Temp
*PtrC\P1 = (alphaB * *PtrB\P1 + (((255-alphaB)*alphaA * *PtrA\P1 )>>8))>>8
*PtrC\P2 = (alphaB * *PtrB\P2 + (((255-alphaB)*alphaA * *PtrA\P2 )>>8))>>8
*PtrC\P3 = (alphaB * *PtrB\P3 + (((255-alphaB)*alphaA * *PtrA\P3 )>>8))>>8
*PtrA + 4
*PtrB + 4
*PtrC + 4
*PtrT + 4
pos + 4
Wend
EndProcedure
I=-255
p.f=0.1
s.f=0.2
Start=#False
transition.s="019-Whorl01.png"
Repeat
ClearScreen(0)
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
Start=#True
EndIf
If start
If i < 255
Transparence1(transition,I)
I + p
p + s
ElseIf i >= 255
I=255
Transparence1(transition,I)
EndIf
DisplaySprite(#SpriteC,0,0)
Else
DisplaySprite(#SpriteA,0,0)
StartDrawing(ScreenOutput())
DrawText(10,10,"Pressez la touche espace pour commencer...",#Yellow, #Red)
StopDrawing()
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)