j'ai un bug de sprite avec OpenWindowedScreen

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Micheao
Messages : 533
Inscription : dim. 07/déc./2014 10:12
Localisation : Sud-Est

j'ai un bug de sprite avec OpenWindowedScreen

Message par Micheao »

Bonjour

mon code ne defile pas il bug quand je mets OpenWindowedScreen de plus je sais pas ce qui faut mettre comme boucle où faut 'il mettre Select WaitWindowEvent() dans la boucle .
Merci de votre aide

Code : Tout sélectionner

EnableExplicit
InitSprite()
InitKeyboard()

Enumeration
  #Main_Form
EndEnumeration

Global Close_Main,ScreenW.i=800,ScreenH.i=600,x.i,y.i
x.i=ScreenW + 34
y.i=Int(ScreenH/2)


Procedure test()
  If    OpenWindow(#Main_Form,0,0,800,600,"test  ",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
    If OpenWindowedScreen(WindowID(#Main_Form),0,0,ScreenW,ScreenH)
      
      
    
    

    CreateSprite(0,225,64,#PB_Sprite_AlphaBlending)
    StartDrawing(SpriteOutput(0))
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,225,64,RGBA(0,0,0,0))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawText(20,10,"Test  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
    StopDrawing()
   
    Repeat   

  
     DisplayTransparentSprite(0, X, Y, 255)
      ExamineKeyboard()
        x-2
      If x<-225
        x=ScreenWidth()
      EndIf
    Select WaitWindowEvent()      
      Case #PB_Event_CloseWindow
        Close_Main =#True
   EndSelect
    FlipBuffers()
 
    Until KeyboardPushed(#PB_Key_Escape) Or Close_Main
  EndIf
EndIf

  End
EndProcedure
Test()
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: j'ai un bug de sprite avec OpenWindowedScreen

Message par falsam »

Code mininum pour une fenetre 2D utilisant OpenWindowedScreen()

Code : Tout sélectionner

;Initialisation
If InitSprite()
  InitKeyboard()
  InitMouse()
EndIf

;Creation du screen
OpenWindow(0, 0, 0, 800, 600, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

;Load ou creation des média par exemple

;Boucle evenementielle
Repeat  ;Evenement applications
  Repeat ;Evenement OpenWindow() à vider ou à traiter
    Event = WindowEvent()
     
    Select Event    
      Case #PB_Event_CloseWindow
        End
    EndSelect  
  Until Event=0 ;PLus rien à traiter

  ;Ici le code 2D
    
  FlipBuffers()
  ClearScreen(RGB(135, 206, 235))
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: j'ai un bug de sprite avec OpenWindowedScreen

Message par falsam »

Ton code corrigé en tenant compte du squelette précédent

Code : Tout sélectionner

;Initialisation
If InitSprite()
  InitKeyboard()
  InitMouse()
EndIf

;Creation du screen
OpenWindow(0, 0, 0, 800, 600, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

;Ici tu as crée ton sprite
CreateSprite(0,225,64,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,225,64,RGBA(0,0,0,0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawText(20,10,"je fais défiler mon sprite  :)",RGBA(255,255,255,255),RGBA(0,0,0,0));
StopDrawing()

;Initialisation de(s) variable
x = ScreenWidth()

;Boucle evenementielle
Repeat  ;Evenement applications
  Repeat;Evenement OpenWindow() à vider ou à traiter
    Event = WindowEvent()
    
    Select Event    
      Case #PB_Event_CloseWindow
        End
    EndSelect  
  Until Event=0 ;PLus rien à traiter
  
  ;Affichage du sprite 0
  DisplayTransparentSprite(0, x, ScreenHeight()/2)
  
  ;Défilement vers la gauche
  x-1
  If x < -225 ;Taille de ton sprite
    x = ScreenWidth()
  EndIf
    
  FlipBuffers()
  ClearScreen(RGB(135, 206, 235))
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: j'ai un bug de sprite avec OpenWindowedScreen

Message par Ar-S »

Falsam est allé plus vite que moi.
En reprenant ton exemple

Code : Tout sélectionner

 
  ; Pense à initialiser ton clavier, les sprites et ta souris (si besoin) 
InitSprite()
InitKeyboard()
InitMouse()

Enumeration
  #Main_Form
EndEnumeration

Global Close_Main,ScreenW.i=800,ScreenH.i=600,x.i,y.i
x.i=ScreenW + 34
y.i=Int(ScreenH/2)
 
  
If  OpenWindow(#Main_Form,0,0,800,600,"test  ",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(#Main_Form),0,0,ScreenW,ScreenH)
    
    CreateSprite(0,225,64,#PB_Sprite_AlphaBlending)
    StartDrawing(SpriteOutput(0))
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,225,64,RGBA(0,0,0,0))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawText(20,10,"Test  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
    StopDrawing()
    

  direction = 2
  
  Repeat
   
    ExamineMouse() ; au cas ou tu ais besoin de surveiller la souris
    ExamineKeyboard() ; surveille le clavier pour gérer la sortie avec echape
    
    DisplayTransparentSprite(0, X, Y, 255)
      
    
    x-2
    If x<0
      x=ScreenWidth()
    EndIf
    
    DisplaySprite(0, x, x)
    x + direction
    If x > 140 : direction = -2 : EndIf
    If x < 0   : direction =  2 : EndIf
    
; Une fois que tu as fais tes opérations tu utilises ton flipbuffer et tu nettoies ton ecran pour la boucle suivante 
    
    FlipBuffers() 
    ClearScreen(RGB(0, 0, 0))

  
    
  Until KeyboardPushed(#PB_Key_Escape)
  
EndIf
~~~~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
falsam
Messages : 7324
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: j'ai un bug de sprite avec OpenWindowedScreen

Message par falsam »

@Ar-S: Ce n'est pas grave. Par contre l'éternel débat sur les événements de la fenêtre :wink:

Tu ne les vides pas. Par exemple utilises la combinaison de touches ALt + Tab pour sortir de ton exemple puis revient sur l'éxécutable de ton code. ça freeze en principe.
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Micheao
Messages : 533
Inscription : dim. 07/déc./2014 10:12
Localisation : Sud-Est

Re: j'ai un bug de sprite avec OpenWindowedScreen

Message par Micheao »

UN grand merci à vous deux les amis
Répondre