Page 1 sur 1

[ok]Comment affiicher un texte pour quelques secondes

Publié : sam. 30/avr./2016 18:48
par Bernie
Bonsoir
comment faire pour que mon texte soit afficher quelques secondes sur l"écran et disparait ?

merci


Code : Tout sélectionner

EnableExplicit
If  InitSprite()=0 Or InitKeyboard()=0 Or InitSound()=0
  MessageRequester("Erreur", "Impossible d'initialiser le jeux ")
  End
EndIf

;--- Les Constantes 
Enumeration Windows
  #Main_Window
EndEnumeration

Enumeration texte
  #TexteRejouer
  EndEnumeration


  Global gEvent,gWidth=800,gHeight=600,gfont
  gFont = LoadFont(0, "Arial", 18, #PB_Font_Bold )



;---Création de la surface du jeu
OpenWindow(#Main_Window,0,0,gWidth,gHeight,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Main_Window),0,0,gWidth,gHeight)

Procedure Affichetext()
  CreateSprite(#TexteRejouer,90,50,#PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(#TexteRejouer))
DrawingFont(gFont)
DrawText(0,10,"TEST  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
StopDrawing()
  EndProcedure

Affichetext()



Repeat
  Repeat
    gEvent=WindowEvent()
    Select gEvent
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until gEvent=0
  ;--- Partie 2D
  ClearScreen(RGB(0, 0, 0))
  DisplayTransparentSprite(#TexteRejouer, 150, 10)
    ExamineKeyboard()
    FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End

Re: Comment affiicher un texte pour quelques secondes à l'ec

Publié : sam. 30/avr./2016 22:50
par falsam
Hello Bernie.

Objectif afficher le texte durant 5 secondes .

On déclare une variable TopTimer = #True

Code : Tout sélectionner

Global TopTimer.b = #True
On ajoute un timer à la fenêtre qui se déclenchera au bout de 5 secondes

Code : Tout sélectionner

AddWindowTimer(#Main_Window, #TimerText, 5000) 
Quand le timer a atteint les 5 secondes, on le détruit.

Code : Tout sélectionner

RemoveWindowTimer(#Main_Window, #TimerText)
Tant que TopTimer est à #True, on affiche le texte.

Code : Tout sélectionner

If TopTimer = #True
  DisplayTransparentSprite(#TexteRejouer, 150, 10)
EndIf
Le code .

Code : Tout sélectionner

EnableExplicit
If  InitSprite()=0 Or InitKeyboard()=0 Or InitSound()=0
  MessageRequester("Erreur", "Impossible d'initialiser le jeux ")
  End
EndIf

;--- Les Constantes 
Enumeration Timer
  #TimerText
EndEnumeration

Enumeration Windows
  #Main_Window
EndEnumeration

Enumeration texte
  #TexteRejouer
EndEnumeration

;TopTimer
Global TopTimer.b = #True

Global gEvent,gWidth=800,gHeight=600,gfont

gFont = LoadFont(0, "Arial", 18, #PB_Font_Bold )

;---Création de la surface du jeu
OpenWindow(#Main_Window,0,0,gWidth,gHeight,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Main_Window),0,0,gWidth,gHeight)

;Ajouter un timer qui se déclenchera chaque seconde (1 seconde = 1000 millisecondes)
AddWindowTimer(#Main_Window, #TimerText, 5000) 

Procedure Affichetext()
  CreateSprite(#TexteRejouer,90,50,#PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(#TexteRejouer))
  DrawingFont(gFont)
  DrawText(0,10,"TEST  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
  StopDrawing()
EndProcedure

Affichetext()

Repeat
  Repeat
    gEvent=WindowEvent()
    Select gEvent
      Case #PB_Event_Timer 
        TopTimer = #False
        
        ;Le timer est déclenché : Il sera détruit afin de ne plus afficher le texte
        RemoveWindowTimer(#Main_Window, #TimerText)
        
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until gEvent=0
  ;--- Partie 2D
  ClearScreen(RGB(0, 0, 0))
  
  ;Si on a pas atteint les 5 secondes, on affiche le texte
  If TopTimer = #True
    DisplayTransparentSprite(#TexteRejouer, 150, 10)
  EndIf
  
  ExamineKeyboard()
  FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End

Re: Comment affiicher un texte pour quelques secondes à l'ec

Publié : sam. 30/avr./2016 22:54
par microdevweb
Remarque: J'ai utilisé ton code, j'ai juste ajouté quelques code.

2 solutions

Première solution avec un compteur

Code : Tout sélectionner

EnableExplicit
If  InitSprite()=0 Or InitKeyboard()=0 Or InitSound()=0
    MessageRequester("Erreur", "Impossible d'initialiser le jeux ")
    End
EndIf

;--- Les Constantes 
Enumeration Windows
    #Main_Window
EndEnumeration

Enumeration texte
    #TexteRejouer
EndEnumeration


Global gEvent,gWidth=800,gHeight=600,gfont
gFont = LoadFont(0, "Arial", 18, #PB_Font_Bold )
Global Currentime,TimeElapsed,Chrono=1000 ; 1000 millisecondes soit une seconde


;---Création de la surface du jeu
OpenWindow(#Main_Window,0,0,gWidth,gHeight,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Main_Window),0,0,gWidth,gHeight)

Procedure Affichetext()
    CreateSprite(#TexteRejouer,90,50,#PB_Sprite_AlphaBlending)
    StartDrawing(SpriteOutput(#TexteRejouer))
    DrawingFont(gFont)
    DrawText(0,10,"TEST  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
    StopDrawing()
EndProcedure

Affichetext()


; On relève le temps avent la boucle principale
Currentime=ElapsedMilliseconds()
Repeat
    Repeat
        gEvent=WindowEvent()
        Select gEvent
            Case #PB_Event_CloseWindow
                End
        EndSelect
    Until gEvent=0
    ;--- Partie 2D
    ClearScreen(RGB(0, 0, 0))
    ; ICi je calcul le temps écoulé
    TimeElapsed=ElapsedMilliseconds()-Currentime
    ; Ici je teste que le temps est inférieur à la limite décidée
    If TimeElapsed<Chrono
        DisplayTransparentSprite(#TexteRejouer, 150, 10)
    EndIf
    ExamineKeyboard()
    FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End
Deuxième solution en utilisant un WindwosTime

Code : Tout sélectionner

EnableExplicit
If  InitSprite()=0 Or InitKeyboard()=0 Or InitSound()=0
    MessageRequester("Erreur", "Impossible d'initialiser le jeux ")
    End
EndIf

;--- Les Constantes 
Enumeration Windows
    #Main_Window
EndEnumeration
#Timer=0
Enumeration texte
    #TexteRejouer
EndEnumeration


Global gEvent,gWidth=800,gHeight=600,gfont
Global DisplayTxtOn=#True
gFont = LoadFont(0, "Arial", 18, #PB_Font_Bold )
; Une procédure qu sera appelée quand le temps est écoulé
Procedure CallBackTimer()
    DisplayTxtOn=#False
    RemoveWindowTimer(#Main_Window,#Timer)
EndProcedure
;---Création de la surface du jeu
OpenWindow(#Main_Window,0,0,gWidth,gHeight,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Main_Window),0,0,gWidth,gHeight)
; J'atoute un timer à la fenêtre
AddWindowTimer(#Main_Window,#Timer,1000)
BindEvent(#PB_Event_Timer,@CallBackTimer(),#Main_Window)
Procedure Affichetext()
    CreateSprite(#TexteRejouer,90,50,#PB_Sprite_AlphaBlending)
    StartDrawing(SpriteOutput(#TexteRejouer))
    DrawingFont(gFont)
    DrawText(0,10,"TEST  ",RGBA(255,255,255,255),RGBA(0,0,0,0));
    StopDrawing()
EndProcedure

Affichetext()


Repeat
    Repeat
        gEvent=WindowEvent()
        Select gEvent
            Case #PB_Event_CloseWindow
                End
        EndSelect
    Until gEvent=0
    ;--- Partie 2D
    ClearScreen(RGB(0, 0, 0))
    ; Je n'afiche le texte que si le flag est vrai
    If DisplayTxtOn=#True
        DisplayTransparentSprite(#TexteRejouer, 150, 10)
    EndIf
    ExamineKeyboard()
    FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
End

Re: Comment affiicher un texte pour quelques secondes à l'ec

Publié : sam. 30/avr./2016 22:55
par microdevweb
Oups falsam, nos réponses se sont croisées :lol:

Re: Comment affiicher un texte pour quelques secondes à l'ec

Publié : dim. 01/mai/2016 6:59
par Bernie
Merci à vous 2 pour vos réponses