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

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

Message par Dumli »

Oui ça j'avais compris mais je ne comprends pas tellement la formule mathématique. :(
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 »

Code : Tout sélectionner

temps=GetTickCount_()
For x=0 To 20000000
i=(Int(x / 1) & $1) + 1
Next x
Debug GetTickCount_() -temps

temps=GetTickCount_()
For x=0 To 20000000
i=x%2+1  ;;;;;;;;;;;;;;; beaucoup plus rapide
Next x
Debug GetTickCount_() -temps

!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
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

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

Message par Backup »

SPH a écrit : i=x%2+1 ;;;;;;;;;;;;;;; beaucoup plus rapide

tu n'as manifestement pas compris le but de sa formule !

lui il peut faire

i=(Int(x / 10) & $1) + 1

ce qui permet de retourner
11111111112222222222

ce qui permet dans son code , de ne pas changer d'image a chaque boucle !!
mais d'avoir une variante de delay !! (puisqu'il affiche plusieurs fois la meme image (10 fois ici))

le but n'est donc pas la vitesse ! :roll:
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 pense que je vais passer pour un gros boulet ... :roll:
Je comprends l'utilité de la formule. Néanmoins je ne comprends pas la partie soulignée i=(Int(x / 10) & $1) + 1. Pourriez-vous me donner sa traduction en algèbre parcque le & et le $ je piges pas :|
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 »

J'explique la formule, du moins la partie qui change toutes les x valeurs

y = Int(X / 10)
Donc la je divise par 10 pour changer tous les 10
ensuite je travaille en binaire pour savoir si la valeur est pair ou impaire
y & $1
en gros je fais un ET logique
Exemple, si y = 3
en binaire
y = %00000011
$1 = %00000001
donc y & $1 = 1
si y = 4
y = %00000100
$1 = %00000001
donc y & $1 = 0

Donc j'ai une valeur qui passe de 0 à 1 ou 1 à 0 tous les 10
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 »

Ok ! :D Voila ce qui me fallait. Merci tout le monde, je tiens à dire que PureBasic est Parfait parceque sa communautée est Parfaite ! :mrgreen:
Dernière modification par Dumli le dim. 16/mai/2010 10:36, modifié 1 fois.
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 »

(Hors sujet : Qu'il viennent sur mon site prendre la nouvelle version bêta, il s'inscrit et me fais un MP pour être mis dans le groupe bêta :D )
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 »

Salut,

Encore un petit problème :D, je suis maintenant entrain de rendre se programme "jouable". Je voudrais en fait qu'on puisse "creuser" ses galeries ou l'on veut cependant dés que le PacMan ne peut plus creuser, il ne doit pouvoir se déplacer seulement dans les galeries qu'il a creusé. J'arrive a détecter quand il est dans ou en dehors des galeries néanmoins je ne parviens pas à le stopper pour qu'il se "cogne" au bord de la galerie sans se bloquer ...

Voila le code : Désolé si c'est un peu le Bordel (J'ai pourtant fais le ménage :lol:)

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() And InitKeyboard()
      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, "E:\Tom\Documents\PureBasic\Pacman01v6.png")
      LoadSprite(2, "E:\Tom\Documents\PureBasic\Pacman02v6.png")
      LoadSprite(3, "E:\Tom\Documents\PureBasic\Pacman01v6d.png")
      LoadSprite(4, "E:\Tom\Documents\PureBasic\Pacman01v6l.png")
      LoadSprite(5, "E:\Tom\Documents\PureBasic\Pacman02v6.png")
      LoadSprite(6, "E:\Tom\Documents\PureBasic\Pacman01v6u.png")
      LoadSprite(7, "E:\Tom\Documents\PureBasic\Pacman02v6.png")
      
      x=1680
      y=0
      test=1
      
      Repeat
        ExamineKeyboard()
        DisplaySprite(0, 0, 0)
            x + vX
            y + vY
            vX = 0
            vY = 0 
                                   
            If KeyboardPushed(#PB_Key_Right)
              vX = 1
              Pacman = (Int(x / 30) & $1) + 1 
              If SpritePixelCollision(Pacman, x, y, 0, 0, 0)
              EndIf
            EndIf
            If KeyboardPushed(#PB_Key_Left)
              vX = -1
              Pacman = (Int(x / 30) & $1) + 4
              If SpritePixelCollision(Pacman, x, y, 0, 0, 0)
              EndIf
            EndIf
            If KeyboardPushed(#PB_Key_Up)
              vY = -1
              Pacman = (Int(y / 30) & $1) + 6
              If SpritePixelCollision(Pacman, x, y, 0, 0, 0)
              EndIf
            EndIf
            If KeyboardPushed(#PB_Key_Down)
              vY = 1
              Pacman = (Int(y / 30) & $1) + 2
              If SpritePixelCollision(Pacman, x, y, 0, 0, 0)
              EndIf
            EndIf
            
            If KeyboardPushed(#PB_Key_Z)
              test = 0
            EndIf
            
            If x > DesktopWidth(0)-25
              x-3
            EndIf
            If x < DesktopWidth(0)-DesktopWidth(0)
              x+3
            EndIf
            If y > DesktopHeight(0)-25
              y-3
            EndIf
            If y < DesktopHeight(0)-DesktopHeight(0)
              y+3
            EndIf 
            
          DisplayTransparentSprite(Pacman, x, y)
          
          If test=1
            StartDrawing(SpriteOutput(0))
              Circle(x+12,y+12,15,#Black) 
            StopDrawing()
          EndIf   
        FlipBuffers()
           
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
        
      Until KeyboardPushed(#PB_Key_Escape)
      
    EndIf
  EndIf
EndIf
Merci d'avance, cependant je ne pourrais pas vous répondre ce soir. :( Mais dés demain matin :mrgreen:
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 »

Version sans image, plus sympa pour partager :)

J'ai revu ton code, je te laisse regarder
Touche "Espace" pour arrêter de creuser ou recommencer à creuser

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() And InitKeyboard()
    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()
      
      #Pacman_Dimension = 25
      ; Pacman va vers la droite
      CreateSprite(1, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(1))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 2 / 3, #Pacman_Dimension * 1 / 3, 2, $000000)
        Line(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2 + 1, 1, $000000)
      StopDrawing()
      CreateSprite(2, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(2))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension * 1 / 3, 2, $000000)
        For n = 0 To #Pacman_Dimension / 2
          Line(#Pacman_Dimension / 2 + n, #Pacman_Dimension / 2 + n, #Pacman_Dimension / 2 - n + 1, 1, $000000)
          Line(#Pacman_Dimension / 2 + n, #Pacman_Dimension / 2 - n, #Pacman_Dimension / 2 - n + 1, 1, $000000)
        Next
      StopDrawing()
      ; Pacman va vers la gauche
      CreateSprite(3, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(3))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 1 / 3, #Pacman_Dimension * 1 / 3, 2, $000000)
        Line(0, #Pacman_Dimension / 2, #Pacman_Dimension / 2 + 1, 1, $000000)
      StopDrawing()
      CreateSprite(4, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(4))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension * 1 / 3, 2, $000000)
        For n = 0 To #Pacman_Dimension / 2
          Line(0, #Pacman_Dimension / 2 + n, #Pacman_Dimension / 2 - n + 1, 1, $000000)
          Line(0, #Pacman_Dimension / 2 - n, #Pacman_Dimension / 2 - n + 1, 1, $000000)
        Next
      StopDrawing()
      ; Pacman va vers le haut
      CreateSprite(5, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(5))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 1 / 3, #Pacman_Dimension * 1 / 3, 2, $000000)
        Line(#Pacman_Dimension / 2, 0, 1, #Pacman_Dimension / 2 + 1, $000000)
      StopDrawing()
      CreateSprite(6, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(6))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 1 / 3, #Pacman_Dimension / 2, 2, $000000)
        For n = 0 To #Pacman_Dimension / 2
          Line(#Pacman_Dimension / 2 + n, 0, 1, #Pacman_Dimension / 2 - n + 1, $000000)
          Line(#Pacman_Dimension / 2 - n, 0, 1, #Pacman_Dimension / 2 - n + 1, $000000)
        Next
      StopDrawing()
      ; Pacman va vers le bas
      CreateSprite(7, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(7))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 2 / 3, #Pacman_Dimension * 2 / 3, 2, $000000)
        Line(#Pacman_Dimension / 2, #Pacman_Dimension / 2, 1, #Pacman_Dimension / 2 + 1, $000000)
      StopDrawing()
      CreateSprite(8, #Pacman_Dimension, #Pacman_Dimension)
      StartDrawing(SpriteOutput(8))
        Circle(#Pacman_Dimension / 2, #Pacman_Dimension / 2, #Pacman_Dimension / 2, $00FFFF)
        Circle(#Pacman_Dimension * 2 / 3, #Pacman_Dimension / 2, 2, $000000)
        For n = 0 To #Pacman_Dimension / 2
          Line(#Pacman_Dimension / 2 + n, #Pacman_Dimension / 2 + n, 1, #Pacman_Dimension / 2 - n + 1, $000000)
          Line(#Pacman_Dimension / 2 - n, #Pacman_Dimension / 2 + n, 1, #Pacman_Dimension / 2 - n + 1, $000000)
        Next
      StopDrawing()
      
      x = 0
      y = 0
      Creuse = 1
      Pacman = 1
      #Avance = 2
      
      Repeat
        ExamineKeyboard()
        
        ; Déplacement
        vX = 0
        vY = 0
        If KeyboardPushed(#PB_Key_Right)
          vX + #Avance
          Pacman = 1
        ElseIf KeyboardPushed(#PB_Key_Left)
          vX - #Avance
          Pacman = 3
        ElseIf KeyboardPushed(#PB_Key_Up)
          vY - #Avance
          Pacman = 5
        ElseIf KeyboardPushed(#PB_Key_Down)
          vY + #Avance
          Pacman = 7
        EndIf
        
        ; Collision avec le bord de l'écran
        If x + vX >= DesktopWidth(0) - #Pacman_Dimension Or x + vX < 0
          vX = 0
        EndIf
        If y + vY >= DesktopHeight(0) - #Pacman_Dimension Or y + vY < 0
          vY = 0
        EndIf
        
        ; Collision avec les tunnels
        If Creuse = 0
          If SpritePixelCollision(Pacman, x + vX, y + vY, 0, 0, 0)
            ; Si on touche, on regarde si on ne peut pas aider le déplacement en bougeant un peu le pacman, c'est pour aider lors des changements de directions dans les tunnels en T
            If vX And SpritePixelCollision(Pacman, x + vX, y + #Avance, 0, 0, 0) = 0
              vY + #Avance
            ElseIf vX And SpritePixelCollision(Pacman, x + vX, y - #Avance, 0, 0, 0) = 0
              vY - #Avance
            ElseIf vY And SpritePixelCollision(Pacman, x + #Avance, y + vY, 0, 0, 0) = 0
              vX + #Avance
            ElseIf vY And SpritePixelCollision(Pacman, x - #Avance, y + vY, 0, 0, 0) = 0
              vX - #Avance
            Else ; Sinon, on bloque le déplacement
              vX = 0
              vY = 0
            EndIf
          EndIf
        EndIf
        
        ; On déplace
        x + vX
        y + vY
        
        ; On creuse
        If KeyboardReleased(#PB_Key_Space)
          Creuse = 1 - Creuse ; Pour faire basculer de 1 à 0 ou de 0 à 1 la valeur
        EndIf
        If Creuse = 1
          StartDrawing(SpriteOutput(0))
            Circle(x + #Pacman_Dimension / 2, y + #Pacman_Dimension / 2, #Pacman_Dimension / 2 + #Avance / 2, #Black)
          StopDrawing()
        EndIf
        
        ; On affiche
        Pacman_Animation = Int((x + y) / (#Avance * 8)) & $1
        DisplaySprite(0, 0, 0)
        DisplayTransparentSprite(Pacman + Pacman_Animation, x, y)
        FlipBuffers()
        
        ; Gestion des évènements windows
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
        
      Until KeyboardPushed(#PB_Key_Escape)
      
    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)]
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 »

Mise à jour du code :
Meilleure gestion des collisions pour faciliter le passage dans les tunnel en T
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 »

8O Chapeau Bas. Franchement bravo, je te remercie pour la rapidité et la qualité de ta réponse. Je vais bosser le code pour en comprendre les moindres détails :mrgreen:

J'ai eu l'idée de le mettre en réseau local, est-ce inimaginable ou ça reste envisageable ? :roll:
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 »

ça risque d'être très dur pour un débutant mais tu peux toujours essayer. Je te conseille avant de se lancer dans le réseau d'arriver à le faire marcher en multijoueur sur un même clavier au début.
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 »

Ok parce que pour le réseau y faut savoir gérer les adresses mémoires et company je crois :? Et je compte bien le mettre en Multi sur 1seul clavier cependant auparavant j'ai déjà eu un problème avec les touches, quand trop de touche (3 ou 4 seulement) sont pressées ça ne fonctionne plus. Comment y remédier ? :twisted:
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 »

bizarre ça ?

un petit exemple sous la main ?
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)]
Répondre