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

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message 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. :)
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

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

Message 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++
Jbernard13
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

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

Message par djes »

Il y a plusieurs tutos là dessus, des effets de loupes par exemple; cherche sur codearchiv et dans les forums.
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message par Dumli »

Désolé de mon absence. Merci pour vos réponses :D
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message 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 ? :|
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
Avatar de l’utilisateur
SPH
Messages : 4949
Inscription : mer. 09/nov./2005 9:53

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

Message 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:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message par Dumli »

Comment rendre le noir transparent ? Je crois que le .bmp l'est directement non ? :?
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
Avatar de l’utilisateur
SPH
Messages : 4949
Inscription : mer. 09/nov./2005 9:53

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

Message par SPH »

En utilisant "DisplayTransparentSprite" pour afficher le pacman, oui, le noir sera transparent :wink:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
venom
Messages : 3138
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

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

Message 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:




@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

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

Message par Ar-S »

Attention, pense à mettre des images en PNG sit tu veux jouer avec la transparence.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
SPH
Messages : 4949
Inscription : mer. 09/nov./2005 9:53

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

Message 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

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message 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
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

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

Message 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
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Dumli
Messages : 75
Inscription : dim. 14/févr./2010 22:28
Localisation : Sud de la France

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

Message 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
Windows 7 Ultimate 64-Bit | Intel Core i5 CPU 750 @ 2.67GHz | 4,0 GB RAM | Sapphire Vapor-X ATI Radeon HD 4890 | 2,5 TeraOctet 7200 RPM
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

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

Message 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 ;)
Répondre