Page 1 sur 2

Comment créer un Screen() avec un fond transparent

Publié : dim. 14/févr./2010 22:35
par Dumli
Salut,

Je voudrais savoir comment créer un Screen () avec un fond transparent (qu'on puisse voir le Bureau). Et aussi comment programmer une "bande noire" qui recouvre progressivement l'écran (en l'occurrence le Screen() transparent),avec des Sprites, ou une Image Noire qui se déplace ? Je ne sais pas. Voilà.

Merci d'avance. :)

Re: Comment créer un Screen() avec un fond transparent

Publié : mar. 16/févr./2010 7:35
par jbernard13
Bonjour
deja présente toi en premier , on connais pas ton niveau de programation.
Ensuite voir ici les tutos :
http://www.purebasic.fr/french/viewtopic.php?f=1&t=6664
http://tripamort.free.fr/tuto.php

a++

Re: Comment créer un Screen() avec un fond transparent

Publié : mar. 16/févr./2010 11:37
par djes
Il y a plusieurs tutos là dessus, des effets de loupes par exemple; cherche sur codearchiv et dans les forums.

Re: Comment créer un Screen() avec un fond transparent

Publié : mer. 12/mai/2010 19:38
par Dumli
Désolé de mon absence. Merci pour vos réponses :D

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 12:41
par Dumli
Voila mon programme est terminé :P Ce n'est rien de bien méchant. :lol:

Pour l'exécuter il faut 3images qui sont Image, Image et Image Vous devez aussi modifier dans le code source le répertoire des images.
:!: ATTENTION NE SE FERME QUE PAR LE GESTIONNAIRE DES TACHES OU A L'AIDE DE LA TOUCHE WINDOW :!:

Regardez jusqu'à la fin. :mrgreen:

Code : Tout sélectionner

;CopyRight Dumli ///\\\
;14/05/2010

ExamineDesktops()
hImage=CreateImage(0,DesktopWidth(0) ,DesktopHeight(0)) ;Capture d'écran
hDC=StartDrawing(ImageOutput(0))
  DeskDC=GetDC_(GetDesktopWindow_())
  BitBlt_(hDC,0,0,DesktopWidth(0) ,DesktopHeight(0) ,DeskDC,0,0,#SRCCOPY)
StopDrawing()
ReleaseDC_(GetDesktopWindow_(),DeskDC)

x=-25
x1=-25
x2=-25
x3=-25
y1=DesktopHeight(0)/4
y2=DesktopHeight(0)/4+DesktopHeight(0)/4
y3=DesktopHeight(0)/4+2*(DesktopHeight(0)/4)
min=70-1
max=140-1
min2=40-1
max2=80-1
vit=5
tx=400
ty=100


If LoadImage(1,"E:\Pictures\Pacman01v6.bmp") And LoadImage(2,"E:\Pictures\Pacman02v6.bmp") And LoadImage(3,"E:\Pictures\Dumli.bmp") ;Charge les 2 positions du PacMan
  If OpenWindow(0,0,0,DesktopWidth(0) ,DesktopHeight(0),"",#PB_Window_Tool|#PB_Window_BorderLess)
    ImageGadget(0,0,0,DesktopWidth(0),DesktopHeight(0) ,ImageID(0)) ;Affiche la capture d'écran
    
    Repeat
      If y3<DesktopHeight(0)
        If x<DesktopWidth(0)
          x+vit
          x1+vit
          x2+vit
          x3+vit
          If pos>max-5  ;Intitialise la Position de la bouche
            pos=0
          EndIf
          If pos>-1 And pos<min  ;Position bouche ouverte
            If StartDrawing(WindowOutput(0))
                DrawImage(ImageID(1),x,y,40,40)
                DrawImage(ImageID(1),x1,y1,40,40)
                DrawImage(ImageID(1),x2,y2,40,40)
                DrawImage(ImageID(1),x3,y3,40,40)
               StopDrawing()
            EndIf 
            pos+2
          EndIf 
          If pos>min And pos<max   ;Position bouche fermée
            If StartDrawing(WindowOutput(0))
                DrawImage(ImageID(2),x,y,40,40)
                DrawImage(ImageID(2),x1,y1,40,40)
                DrawImage(ImageID(2),x2,y2,40,40)
                DrawImage(ImageID(2),x3,y3,40,40)
               StopDrawing()
            EndIf 
            pos+2
          EndIf
          Delay(15)
         Else ;Intitialise les position en x si x>DesktopWidth()
            x=-25
            x1=-25
            x2=-25
            x3=-25
            y=y+35
            y1=y1+35
            y2=y2+35
            y3=y3+35
         EndIf 
       Else ;Intitialise les position en y si y>DesktopHeight()
          
          Repeat
            If tx<1000
                If StartDrawing(WindowOutput(0))
                    DrawImage(ImageID(3),(DesktopWidth(0)/2)-tx/2,(DesktopHeight(0)/2)-ty/2,tx,ty)
                   StopDrawing()
                EndIf
                tx+4
                ty+1
                Delay(10)
            Else
            
              Repeat
                x+5
                If pos>max2-5  ;Intitialise la Position de la bouche
                  pos=0
                EndIf
                If pos>-1 And pos<min2  ;Position bouche ouverte
                  If StartDrawing(WindowOutput(0))
                       DrawImage(ImageID(1),x,(DesktopHeight(0)/2)-200/2,200,200)
                     StopDrawing()
                  EndIf 
                  pos+2
                EndIf 
                If pos>min2 And pos<max2   ;Position bouche fermée
                  If StartDrawing(WindowOutput(0))
                       DrawImage(ImageID(2),x,(DesktopHeight(0)/2)-200/2,200,200)
                     StopDrawing()
                  EndIf 
                  pos+2
                EndIf
                Delay(10)
              ForEver
              
            EndIf
          ForEver
       
       EndIf              
    ForEver
    
  EndIf
Else 
  MessageRequester("Error","Can't Load File")
EndIf
Vous en pensez quoi ? :|

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 13:06
par SPH
J'aime bien. C'est un bon debut. Le pacman pourrait etre un sprite avec noir transparent. Le code pourrait etre réduit de 75% mais tu n'es pas a blamer, je faisais pareil (pire ?) aussi au début :mrgreen:

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 13:11
par Dumli
Comment rendre le noir transparent ? Je crois que le .bmp l'est directement non ? :?

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 13:49
par SPH
En utilisant "DisplayTransparentSprite" pour afficher le pacman, oui, le noir sera transparent :wink:

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 13:58
par venom
Bonjour,

tu doit te servir de la fonction TransparentSpriteColor()

voici un code pour te montrée :

Code : Tout sélectionner

InitSprite() 
InitKeyboard() 
 
;Constantes 
Enumeration
#image
EndEnumeration
 
;- Création de la fenêtre principale 
MaFenetre = OpenScreen(800,600,32,"") 
If MaFenetre  = 0 
  MessageRequester("Erreur", "Impossible d'ouvrir une fenêtre DirectX", #PB_MessageRequester_Ok) 
EndIf

;- chargement du menu
LoadSprite(#image, "c:/image.bmp", 0)

Repeat 
  ClearScreen(RGB(0,0,0)) 

;- position du menu 
DisplayTransparentSprite(#image, 60, 20)
 TransparentSpriteColor(#image, RGB(255, 0, 255)) ; <= ici ont determine la couleur qui deviendra transparent en locurence le rose ici pour le noir c'est RGB(0, 0, 0)

  ExamineKeyboard()   
  FlipBuffers() 
Until KeyboardPushed(#PB_Key_Escape) 
et l'image test :wink:

http://www.hiboox.fr/go/images/dessin/i ... 7.bmp.html
mais regarde section jeux du forum :wink:




@++

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 13:59
par Ar-S
Attention, pense à mettre des images en PNG sit tu veux jouer avec la transparence.

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 14:03
par SPH
Ar-S a écrit :Attention, pense à mettre des images en PNG sit tu veux jouer avec la transparence.
Ou en BMP avec displaytransparentsprite

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 14:08
par Dumli
Je ne comprends pas. J'essaie de mettre mon programme en WindowedScreen(). Quand je le lance, je ne vois que 1 sprite sur 4 et en plus seulement pendant 50 pixels.
J'ai essayé en PNG et c'est pareil.

Code : Tout sélectionner

;CopyRight Dumli ///\\\
;14/05/2010

InitSprite()

ExamineDesktops()
hImage=CreateImage(0,DesktopWidth(0) ,DesktopHeight(0)) ;Capture d'écran
hDC=StartDrawing(ImageOutput(0))
  DeskDC=GetDC_(GetDesktopWindow_())
  BitBlt_(hDC,0,0,DesktopWidth(0) ,DesktopHeight(0) ,DeskDC,0,0,#SRCCOPY)
StopDrawing()
ReleaseDC_(GetDesktopWindow_(),DeskDC)

UsePNGImageDecoder()

x1=-25
x2=-25
x3=-25
x4=-25
y1=0
y2=DesktopHeight(0)/4
y3=DesktopHeight(0)/4+DesktopHeight(0)/4
y4=DesktopHeight(0)/4+2*(DesktopHeight(0)/4)
min=70-1
max=140-1
min2=40-1
max2=80-1
vit=2
tx=400
ty=100


If LoadImage(1,"\Pacman01v6.bmp") And LoadImage(2,"\Pacman02v6.bmp") And LoadImage(3,"\Dumli.bmp") ;Charge les 2 positions du PacMan
  If OpenWindow(0,0,0,DesktopWidth(0) ,DesktopHeight(0),"",#PB_Window_Tool|#PB_Window_BorderLess)
    If OpenWindowedScreen(WindowID(0),0,0,1680 ,1050,0,0,0)
    
      CreateSprite(0,DesktopWidth(0),DesktopHeight(0))
        StartDrawing(SpriteOutput(0))
          DrawImage(ImageID(0),0,0,DesktopWidth(0),DesktopHeight(0))
        StopDrawing()
          
      CreateSprite(1,40,40) 
      CreateSprite(2,40,40)    
      CreateSprite(3,40,40)    
      CreateSprite(4,40,40)
      
      Repeat
        FlipBuffers()
        ClearScreen(RGB(0,0,0))
        DisplaySprite(0,0,0)
        DisplayTransparentSprite(1,x1,y1)
        DisplayTransparentSprite(2,x2,y2)
        DisplayTransparentSprite(3,x3,y3)
        DisplayTransparentSprite(4,x4,y4)
        If y3<DesktopHeight(0)
          If x1<DesktopWidth(0)
            x1+vit
            x2+vit
            x3+vit
            x4+vit
            If pos>max-5  ;Intitialise la Position de la bouche
              pos=0
            EndIf
            If pos>-1 And pos<min  ;Position bouche ouverte
              If StartDrawing(SpriteOutput(3))
                DrawImage(ImageID(1),x1,y1,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(1))
                DrawImage(ImageID(1),x2,y2,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(3))
                DrawImage(ImageID(1),x3,y3,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(4))
                DrawImage(ImageID(1),x4,y4,40,40)
              StopDrawing() : EndIf 
              pos+2
            EndIf 
            If pos>min And pos<max   ;Position bouche fermée
              If StartDrawing(SpriteOutput(2))
                DrawImage(ImageID(2),x1,y1,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(1))
                DrawImage(ImageID(2),x2,y2,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(3))
                DrawImage(ImageID(2),x3,y3,40,40)
              StopDrawing() : EndIf
              If StartDrawing(SpriteOutput(4))
                DrawImage(ImageID(2),x4,y4,40,40)
              StopDrawing() : EndIf 
              pos+2
            EndIf
            Delay(15)
           Else ;Intitialise les position en x si x>DesktopWidth()
              x1=-25
              x2=-25
              x3=-25
              x4=-25
              y1=y1+35
              y2=y2+35
              y3=y3+35
              y4=y4+35
           EndIf 
         Else ;Intitialise les position en y si y>DesktopHeight()
            
            Repeat
              Debug pos
              If tx<1000
                  If StartDrawing(WindowOutput(0))
                      DrawImage(ImageID(3),(DesktopWidth(0)/2)-tx/2,(DesktopHeight(0)/2)-ty/2,tx,ty)
                     StopDrawing()
                  EndIf
                  tx+4
                  ty+1
                  Delay(10)
              Else
              
                Repeat
                  x+5
                  If pos>max2-5  ;Intitialise la Position de la bouche
                    pos=0
                  EndIf
                  If pos>-1 And pos<min2  ;Position bouche ouverte
                    If StartDrawing(WindowOutput(0))
                         DrawImage(ImageID(1),x,(DesktopHeight(0)/2)-200/2,200,200)
                       StopDrawing()
                    EndIf 
                    pos+2
                  EndIf 
                  If pos>min2 And pos<max2   ;Position bouche fermée
                    If StartDrawing(WindowOutput(0))
                         DrawImage(ImageID(2),x,(DesktopHeight(0)/2)-200/2,200,200)
                       StopDrawing()
                    EndIf 
                    pos+2
                  EndIf
                  Delay(10)
                ForEver
                
              EndIf
            ForEver
         
         EndIf              
      ForEver
      
    EndIf
  EndIf
Else 
  MessageRequester("Error","Can't Load File")
EndIf

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 14:44
par Le Soldat Inconnu
un petit exemple :

Fais attention au LoadSprite(, il faut remettre tes images.

Code : Tout sélectionner

ExamineDesktops()
CreateImage(0, DesktopWidth(0), DesktopHeight(0)) ; Capture d'écran
hDC = StartDrawing(ImageOutput(0))
  DeskDC = GetDC_(GetDesktopWindow_())
  BitBlt_(hDC, 0, 0, DesktopWidth(0), DesktopHeight(0), DeskDC, 0, 0, #SRCCOPY)
StopDrawing()
ReleaseDC_(GetDesktopWindow_(), DeskDC)

UsePNGImageDecoder()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_BorderLess | #PB_Window_Maximize)
  
	If InitSprite()
		If OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 1, 0, 0, #PB_Screen_WaitSynchronization)
      
      CreateSprite(0, DesktopWidth(0), DesktopHeight(0))
      StartDrawing(SpriteOutput(0))
        DrawImage(ImageID(0), 0, 0)
      StopDrawing()
      LoadSprite(1, "Pacman01v6.png")
      LoadSprite(2, "Pacman02v6.png")
      LoadSprite(3, "Dumli.png")
      
			x = 0
			y = 100
			
      Repeat
        DisplaySprite(0, 0, 0)
				x + 1
				Pacman = (Int(x / 10) & $1) + 1
				Debug Pacman
        DisplayTransparentSprite(Pacman, x, y)
				If x > DesktopWidth(0)
					x = 0
				EndIf
        FlipBuffers()
				
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
        
      ForEver
      
    EndIf
  EndIf
EndIf

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 15:12
par Dumli
Merci beaucoup. Ya juste une ligne que je ne comprends pas c'est

Code : Tout sélectionner

Pacman = (Int(x / 10) & $1) + 1
Voila aprés quelques petits bidouillages :o (Merci LSI :wink: )

Code : Tout sélectionner

ExamineDesktops()
CreateImage(0, DesktopWidth(0), DesktopHeight(0)) ; Capture d'écran
hDC = StartDrawing(ImageOutput(0))
  DeskDC = GetDC_(GetDesktopWindow_())
  BitBlt_(hDC, 0, 0, DesktopWidth(0), DesktopHeight(0), DeskDC, 0, 0, #SRCCOPY)
StopDrawing()
ReleaseDC_(GetDesktopWindow_(), DeskDC)

UsePNGImageDecoder()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_BorderLess | #PB_Window_Maximize)
  
   If InitSprite()
      If OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 1, 0, 0, #PB_Screen_WaitSynchronization)
      
      CreateSprite(0, DesktopWidth(0), DesktopHeight(0))
      StartDrawing(SpriteOutput(0))
        DrawImage(ImageID(0), 0, 0)
      StopDrawing()
      LoadSprite(1, "\Pacman01v6.png")
      LoadSprite(2, "\Pacman02v6.png")
      LoadSprite(3, "\Dumli.png")
      
         x = -1080
         y = 100
         
      Repeat
        DisplaySprite(0, 0, 0)
            x + 1
            Pacman = (Int(x / 15) & $1) + 1
        For y=-20 To 1050 Step 20
          DisplayTransparentSprite(Pacman, x=x+y, y)
          CreateSprite(y+20, 1700, 20)
            StartDrawing(SpriteOutput(y+20))
              Box(x=x+y, y, 1700, 20)
            StopDrawing()     
        Next y
            If x > DesktopWidth(0)
               x = -1080
            EndIf
        FlipBuffers()
            
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
        
      ForEver
      
    EndIf
  EndIf
EndIf

Re: Comment créer un Screen() avec un fond transparent

Publié : ven. 14/mai/2010 17:28
par Backup
Dumli a écrit :Merci beaucoup. Ya juste une ligne que je ne comprends pas c'est

Code : Tout sélectionner

Pacman = (Int(x / 10) & $1) + 1
ben t'es programmeur non ?

tu fait ça pour mettre sa formule a l'épreuve

Code : Tout sélectionner

For x=0 To 5
    Debug  (Int(x / 1) & $1) + 1
Next x

et tu verra qu'elle renvoi 1212121212121212121

si tu fais ça

Code : Tout sélectionner

For x=0 To 5
    Debug  (Int(x / 3) & $1) + 1
Next x

ho !!! étonnant

ça renvoie :
111222111222111222111222
bref c'est la dessus qu'es basé l'animation de son sprite pacman ;)