Ci-dessous un contre exemple pour démontrer que sans cette notion de timeout, ton explication n'est pas bonne. Juste pour te faire raler
Déplace le sprite avec les flèches gauche et droite. Il y a un temps d'attente quand on change le sens de déplacement si on garde ta façon de faire.
Par contre si tu commentes Event = WaitWindowEvent() et décommentes WindowEvent(), il n'y a plus de temps d'attente.
Code : Tout sélectionner
Enumeration
#MainForm
EndEnumeration
Global Event, GEvent, TEvent
Global Player,PlayerSpeed = 2
Global Ground, x=350, y=450
Global GameEnd = #False
Procedure GamePreload()
;Creation du player
Player = CreateSprite(#PB_Any, 100, 100)
StartDrawing(SpriteOutput(Player))
Box(0, 0, 100, 100, RGBA(255, 228, 196, 255))
Circle(20, 30, 10, RGBA(210, 180, 140, 255))
Circle(80, 30, 10, RGBA(210, 180, 140, 255))
Box(40, 50, 20, 20, RGBA(210, 180, 140, 255))
Box(30, 75, 40, 10, RGBA(210, 180, 140, 255))
StopDrawing()
;Creation du sol
Ground = CreateSprite(#PB_Any, 800, 50)
StartDrawing(SpriteOutput(Ground))
Box(0, 0, 800, 50, RGBA(205, 133, 63, 255))
StopDrawing()
EndProcedure
Procedure GameUpdate()
If KeyboardPushed(#PB_Key_Left) And x > PlayerSpeed
x-PlayerSpeed
EndIf
If KeyboardPushed(#PB_Key_Right) And x < 800-SpriteWidth(Player)-PlayerSpeed
x+PlayerSpeed
EndIf
DisplaySprite(Player, x, y)
DisplaySprite(Ground, 0, 550)
EndProcedure
Procedure GameStart()
Protected Width = 800
Protected Height = 600
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
GameEnd = #True
EndIf
If OpenWindow(#mainform, 0, 0, Width, Height, "New Game", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(#mainform), 0, 0, Width, Height)
GamePreload()
EndIf
EndIf
Repeat
;Repeat
;Event = WindowEvent()
Event = WaitWindowEvent()
GEvent = EventGadget()
TEvent = EventType()
Select event
Case #PB_Event_CloseWindow
GameEnd = #True
EndSelect
;Until event=0
FlipBuffers()
ClearScreen(RGB(255,255,255))
ExamineKeyboard()
GameUpdate()
Until KeyboardPushed(#PB_Key_Escape) Or GameEnd = #True
EndProcedure
GameStart()