Aide : code Darkbasic en PureBasic

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
leoneo
Messages : 35
Inscription : sam. 24/janv./2004 19:49

Aide : code Darkbasic en PureBasic

Message par leoneo »

Salut, voila g un ancien code en DB qui permet de faire des effets avec des images et je voudrai l'utiliser en PureBasic mais il n'y a pas d'equivalent pour la fct : copy bitmap ( en DB)

voici le code en DB :

Code : Tout sélectionner

remstart
   TRANS-FX v1.0
   release date: 12/1/2000

   Written by Guy P. Savoie
   Submitted to the Dark BASIC community as public domain.

   Description:
   This function allows the user to code transitions
   between 2D screens.

   The function assumes all bitmaps exist and are the same dimensions.
   Most transitions require the height and width to be divisible by 40.

   transFX(fxnum,bmp1,bmp2,dest,delay,addsync)

   bmp1 is the original bitmap, bmp2 is the new bitmap,
   dest is the destination bitmap for the transition screens (usually bitmap 0)
   dest and bmp1 can and often should be the same.
   delay is the millesecond delay added between each frame of transition.
   addsync will add a SYNC command after each transition step (needed if you have SYNC ON.

   fxnum can be:
   1  left to right wipe
   2  right to left
   3  wipe down
   4  wipe up
   5  block chase wipe 1
   6  block chase wipe 2
   7  block chase wipe 3
   8  block chase wipe 4
   9  random block wipe
   10 slide right
   11 slide left
   12 slide down
   13 slide up
remend

function transFX(fxnum,bmp1,bmp2,dest,delay,addsync)
   cb = current bitmap()
   set current bitmap dest
   scrW = screen width()
   scrH = screen height()
   set current bitmap cb
   if bmp1 <> dest then copy bitmap bmp1, dest

   if fxnum = 1 : ` left to right wipe
      bwide = 10
      count = scrW / bwide
      for i = 0 to count - 1
         copy bitmap bmp2,i*bwide,0,((i+1)*bwide)-1,scrH-1 ,dest,i*bwide,0,((i+1)*bwide)-1,scrH-1
         if addsync then sync
         if delay > 0 then wait delay
      next x
      exitfunction
   endif

   if fxnum = 2  : ` right to left wipe
      bwide = 10
      count = scrW / bwide
      for i = count - 1 to 0 step -1
         copy bitmap bmp2,i*bwide,0,((i+1)*bwide)-1,scrH-1 ,dest,i*bwide,0,((i+1)*bwide)-1,scrH-1
         if addsync then sync
         if delay > 0 then wait delay
      next x
      exitfunction
   endif

   if fxnum = 3  : ` wipe down
      bheight = 10
      count = scrh / bheight
      for i = 0 to count - 1
         copy bitmap bmp2,0,i*bheight,scrW-1,((i+1)*bheight)-1,dest,0,i*bheight,scrW-1,((i+1)*bheight)-1
         if addsync then sync
         if delay > 0 then wait delay
      next x
      exitfunction
   endif

   if fxnum = 4  : ` wipe down
      bheight = 10
      count = scrh / bheight
      for i = count - 1 to 0 step -1
         copy bitmap bmp2,0,i*bheight,scrW-1,((i+1)*bheight)-1,dest,0,i*bheight,scrW-1,((i+1)*bheight)-1
         if addsync then sync
         if delay > 0 then wait delay
      next x
      exitfunction
   endif

   if fxnum = 5  : ` block wipe
      bheight = 40
      bwidth = 40
      xcount = scrW / bwidth
      ycount = scrh / bheight
      for y = 0 to ycount-1
         for x = 0 to xcount-1
            copy bitmap bmp2,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1,dest,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1
            if addsync then sync
            if delay > 0 then wait delay
         next x
      next y
      exitfunction
   endif

   if fxnum = 6  : ` block wipe 2
      bheight = 40
      bwidth = 40
      xcount = scrW / bwidth
      ycount = scrh / bheight
      for y = ycount-1 to 0 step -1
         for x = xcount-1 to 0 step -1
            copy bitmap bmp2,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1,dest,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1
            if addsync then sync
            if delay > 0 then wait delay
         next x
      next y
      exitfunction
   endif

   if fxnum = 7  : ` block wipe 3
      bheight = 40
      bwidth = 40
      xcount = scrW / bwidth
      ycount = scrh / bheight
      for x = 0 to xcount-1
         for y = 0 to ycount-1
            copy bitmap bmp2,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1,dest,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1
            if addsync then sync
            if delay > 0 then wait delay
         next y
      next x
      exitfunction
   endif

   if fxnum = 8  : ` block wipe 4
      bheight = 40
      bwidth = 40
      xcount = scrW / bwidth
      ycount = scrh / bheight
      for x = xcount-1 to 0 step -1
         for y = ycount-1 to 0 step -1
            copy bitmap bmp2,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1,dest,x*bwidth,y*bheight,((x+1)*bwidth)-1,((y+1)*bheight)-1
            if addsync then sync
            if delay > 0 then wait delay
         next y
      next x
      exitfunction
   endif

   if fxnum = 9 : ` random blocks
      bheight = 40
      bwidth = 40
      xcount = scrW / bwidth
      ycount = scrh / bheight
      fullcount = xcount * ycount
      dim fx_a(fullcount)
      for i = 1 to fullcount
         fx_a(i) = i
      next i
      ` now randomize em...
      for i = 1 to (fullcount - 1)
         spos = rnd(fullcount-i)+i
         if spos > i
            if spos <= fullcount
               tmp = fx_a(spos)
               fx_a(spos) = fx_a(i)
               fx_a(i) = tmp
            endif
         endif
      next i
      for i = 1 to fullcount
         yp = ((fx_a(i)-1)/xcount)
         xp = fx_a(i)-(yp*xcount)-1
         copy bitmap bmp2,xp*bwidth,yp*bheight,((xp+1)*bwidth)-1,((yp+1)*bheight)-1,dest,xp*bwidth,yp*bheight,((xp+1)*bwidth)-1,((yp+1)*bheight)-1
         if addsync then sync
         if delay > 0 then wait delay
      next i
      undim fx_a(fullcount)
      exitfunction
   endif

   if fxnum = 10 : ` push right
      bheight = 0 : ` don't use this here...
      bwidth = 40
      count = scrW / bwidth
      for i = 0 to count - 1
         copy bitmap bmp2,scrw-((i+1)*bwidth),0,scrw-1,scrH-1,dest,0,0,((i+1)*bwidth)-1,scrH-1
         if addsync then sync
         if delay > 0 then wait delay
      next i
   endif

   if fxnum = 11 : ` push left
      bheight = 0 : ` don't use this here...
      bwidth = 40
      count = scrW / bwidth
      for i = 1 to count
         copy bitmap bmp2,0,0,i*bwidth-1,scrH-1,dest,scrW-(i*bwidth),0,scrW-1,scrH-1
         if addsync then sync
         if delay > 0 then wait delay
      next i
   endif

   if fxnum = 12 : ` push down
      bheight = 40
      bwidth = 0
      count = scrH / bheight
      for i = 1 to count
         copy bitmap bmp2,0,scrh-(i*bheight),scrw-1,scrH-1,dest,0,0,scrW-1,(i*bheight)-1
         if addsync then sync
         if delay > 0 then wait delay
      next i
   endif

   if fxnum = 13 : ` push up
      bheight = 40
      bwidth = 0
      count = scrH / bheight
      for i = 1 to count
         copy bitmap bmp2,0,0,scrW-1,i*bheight-1,   dest,0,scrH-(i*bheight),scrW-1,scrH-1
         if addsync then sync
         if delay > 0 then wait delay
      next i
   endif

endfunction

Voici ce ke g tenté de faire en appellant la fct copy bitmap de la dll de DarkBasicPro mais ca ne fonctionne pas :

Code : Tout sélectionner



If InitMouse() = 0 Or InitSprite() = 0 Or InitSprite3D() = 0 Or InitKeyboard() = 0 Or InitMovie()=0 Or InitSound() = 0
  MessageRequester("Erreur", "Le logiciel ne peut pas ouvrir DirectX 7", 0)
  End
EndIf

;
;-------- OpenScreen --------


If OpenScreen(800, 600, 16, "Test") = 0
  MessageRequester("Error", "Impossible d'ouvrir une fenetre de 800*600 16 bit",0)
  End
EndIf


LoadImage(0,"F:\projet tut 2eme\test.bmp")
LoadImage(1,"F:\projet tut 2eme\test1.bmp")
LoadImage(2,"F:\projet tut 2eme\test2.bmp")

ProcedureCDLL copybitmap(BitmapSource.l, Gauche.l, Haut.l, Droite.l, Bas.l, BitmapDestination.l, GaucheD.l, HautD.l, DroiteD.l, BasD.l)
  ; En premier lieu, j'ouvre la DLL 2D -DBProBitmapDebug.dll- 
  If OpenLibrary( 1 , "F:\projet tut 2eme\DBProBitmapDebug.dll" ) 
    ; Je vérifie que la commande que je veut existe dans la DLL ->copybitmap.l 
    copybitmap.l = IsFunction( 1 , "?CopyBitmap@@YAXHH@Z" ) 
    ; Si CopyBitmap existe alors on l'appelle avec les bons paramètres. 
    If copybitmap > 0 
      CallCFunctionFast( copybitmap , BitmapSource, Gauche, Haut, Droite, Bas, BitmapDestination, GaucheD, HautD, DroiteD, BasD) 
     EndIf 
    ; une fois tout terminé, on referme la DLL. 
    CloseLibrary( 1 ) 
   EndIf 
  ; Fin de la commande. 
 EndProcedure




Procedure transfx(fxnum,bmp1,bmp2,dest)

scrW=800
scrH =600
If fxnum = 1 
      bwide = 10
      count = scrW / bwide
      For i = 0 To count - 1
         copybitmap(bmp2,i*bwide,0,((i+1)*bwide)-1,scrH-1 ,dest,i*bwide,0,((i+1)*bwide)-1,scrH-1)
      Next i
   EndIf


EndProcedure
m=0

Repeat
  FlipBuffers()                        
  ClearScreen(0,0,0)                   

  ExamineKeyboard()


 UseImage(2)
 If m=0
transfx(1,0,1,2)
m=1
EndIf

Until KeyboardPushed(#PB_Key_Return)
FreeImage(0)
FreeImage(1)
FreeImage(2)

End


Si vous avez une idée , Merci
leoneo
Messages : 35
Inscription : sam. 24/janv./2004 19:49

Message par leoneo »

PS : Si quelqu'un a un moyen de faire des effets de transition avec les images je suis prenneur !!! Merci
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Il y a la fonction CopyImage(#Image1, #Image2) qui crée une image qui est la copie de #Image1, Sinon, il y a GrabImage(#Image1, #Image2, x, y, Largeur, Hauteur) qui fait la même chose, mais selon les coordonnées que tu fournis.
leoneo
Messages : 35
Inscription : sam. 24/janv./2004 19:49

Message par leoneo »

Merci je vais essayer avec grabimage
Répondre