JoyWait ( [port] )
Parameters
| port (optional) - which joystick to wait on; 0 is the first stick (default) |
Description
|
Halts the program until a joystick button is pressed, then returns its number. JoyWait and WaitJoy are the same command: both names call exactly the same routine in the runtime. WaitJoy is the spelling that matches WaitKey and WaitMouse, so new code usually uses that one. While it waits your loop is stopped - nothing animates and anything drawn to the back buffer stays invisible - so draw the screen and Flip it before calling. During gameplay use JoyHit in your main loop instead so the game keeps running. Heads up: the current DirectX 12 runtime does not enumerate joysticks - it reports zero attached devices - so JoyWait returns 0 immediately instead of waiting. Guard it with JoyType and fall back to WaitKey so a "press fire to start" screen does not flash past. See also: WaitJoy, JoyHit, GetJoy, JoyType, WaitKey. |
Example
; JoyWait Example ; --------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; JoyWait halts the program until a joystick button is pressed and ; returns its number. Draw an explanation frame BEFORE blocking - ; and never block at all when no joystick is attached, because the ; wait could then never end. Cls If JoyType()=0 Then Text 320,200,"No joystick detected - plug in a gamepad to try JoyWait.",True Text 320,220,"JoyWait would halt forever without one, so it is skipped.",True Else Text 320,200,"Press any joystick button to continue...",True End If Flip button=0 If JoyType()>0 Then button=JoyWait() ; blocks until a pad button is pressed While Not KeyDown(1) Cls Text 0,0,"Esc: exit" If button>0 Then Text 0,20,"JoyWait() returned button number "+button Else Text 0,20,"JoyWait() was skipped - no joystick attached." End If Flip Wend End
Index