JoyUDir ( [port] )
Parameters
| port (optional) - which joystick to read; 0, the first attached stick (default) |
Description
|
Returns the joystick's first slider axis as a digital -1, 0 or 1. Where JoyU hands you the slider's exact analogue position, JoyUDir rounds it to three states: -1 once the slider is pushed past a third of its travel one way, 1 past a third the other way, and 0 around the middle. The built-in dead zone means a slightly off-centre slider still reads 0 - no jitter to filter yourself. That is the reading you want when the slider is acting as a switch rather than a dial: flap and gear selectors, cycling through targets, nudging a menu. It belongs to the same family as JoyXDir, JoyYDir and JoyZDir, which digitise the main axes the same way. Note it reports the state, not the change: while the slider sits pushed you get -1 or 1 every frame, so for one-shot actions track the previous value and act only when it changes (the JoyXDir example shows the pattern). Gamepads without slider hardware read 0 here forever. The modern Blitz3D+ runtime does not implement joystick input yet: JoyType always reports 0 and JoyUDir always returns 0 there, whatever is plugged in - so for now the example shows its no-joystick screen. See also: JoyU, JoyVDir, JoyXDir, JoyType. |
Example
; JoyUDir Example ; --------------- Graphics 640,480,0,2 SetBuffer BackBuffer() While Not KeyDown(1) Cls ; JoyUDir boils the U slider down to a digital -1, 0 or 1: ; it reports -1 or 1 once the slider is pushed past a third ; of its travel. Ideal for menu flicks and gear up/down. dir=JoyUDir() If JoyType()=0 Then Text 0,0,"Esc: exit" Text 0,60,"No joystick detected - plug in a stick with a throttle slider." Text 0,80,"With one attached, the lamps below follow the U slider." Else Text 0,0,"Push the U slider to its ends Esc: exit" End If ; Three lamps: -1, 0 and 1 - the current reading lights up For lamp=-1 To 1 x=320+lamp*120 If dir=lamp Then Color 255,220,0 Oval x-35,240,70,70,True Else Color 90,90,90 Oval x-35,240,70,70,False End If Color 255,255,255 Text x,330,lamp,True Next Text 0,20,"JoyUDir() = "+dir Text 0,40,"(raw JoyU() = "+JoyU()+")" Flip Wend End
Index