Bon, c'est un truc vraiment tout bête, mais je le poste quand même au cas où ça intéresserait un débutant.
Il s'agit de réaliser l'ombre d'un sprite (transparent). Pour le moment, l'ombre est uniquement plaquée (pas en perspective, mais c'est faisable avec transformSprite()).
Dans le code, j'ai ajouté un petit bord blanc aux sprites, mais on peut l'enlever sans problème (c'était juste pour tester).
Si vous avez des améliorations ou des remarques n'hésitez pas :
Code : Tout sélectionner
If InitSprite() =0
End
EndIf
w=600
h=400
If OpenWindow(0,0,0,w,h,"Sprite Shadow",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) = 0
End
EndIf
If OpenWindowedScreen(WindowID(0),0,0,w,h) =0
End
EndIf
If LoadSprite(0,#PB_Compiler_Home +"Examples/Sources/Data/Geebee2.bmp") =0
End
Else
a = 6 ; le décallage pour le bord blanc (décallé de 3 * 2)
b = 6 ; le décallage pour les psrites constituant l'ombre floue
; je copie les sprites pour créer une ombre flou avec par la suite
For i =0 To 3
CopySprite(0,i+1)
TransparentSpriteColor(i+1,RGB(255,0,255))
ZoomSprite(i+1,SpriteWidth(0)+a-b*i,SpriteHeight(0)+a-b*i)
Next
; pour le bord blanc du sprite (c'est juste un test)
ZoomSprite(1,SpriteWidth(0)+a,SpriteHeight(0)+a)
; transparence du sprite normale
TransparentSpriteColor(0,RGB(255,0,255))
EndIf
y = -SpriteHeight(0)
x = 10
c = 150 ; distance entre les avions
Repeat
Repeat
EventID = WaitWindowEvent(1)
Select EventId
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until eventId = 0
y -1
If y<-SpriteHeight(0) -20
y = h
EndIf
ClearScreen(RGB(100,100,100))
; on va afficher 4 avions
For i =0 To 3
; affichage de l'ombre flou
DisplayTransparentSprite(1,x+20-b+i*c,y+20-b+i*10,30,0)
DisplayTransparentSprite(2,x+20-b/2+i*c,y+20-b/2+i*10,20,0)
DisplayTransparentSprite(3,x+20+i*c,y+20+i*10,15,0)
; affichage du bord blanc (juste un test)
DisplayTransparentSprite(1,x-a/2+i*c,y-a/2+i*10,255,RGB(255,255,255))
; affichage du sprite normal
DisplayTransparentSprite(0,x+i*c,y+i*10)
Next
FlipBuffers()
Until quit = 1