JoyY# ( [port] )
Parameters
| port (optional) - which joystick to read; 0 is the first stick (default) |
Description
|
Returns the position of the joystick's y-axis as a float from -1 to 1. Fully forward (up) is -1, centred is 0 and fully back (down) is 1, with the whole range in between on an analogue stick. Flight games traditionally use it as it comes, since pushing forward to dive is what a real stick does; anything else usually negates it so that pushing up moves the player up the screen. Because it is a smooth value it suits throttle-like control: multiply by your movement speed and a small lean gives a slow walk while a full push gives a sprint. Use JoyYDir instead when you only want a simple up, down or centred answer. Sticks rarely rest at exactly 0, so ignore small values - a dead zone of about 0.15 - or the player drifts while doing nothing. Heads up: the current DirectX 12 runtime does not enumerate joysticks - it reports zero attached devices - so JoyY returns 0.0 on every port, as does an out-of-range port number. Guard joystick controls with JoyType and keep a keyboard route to everything. See also: JoyX, JoyZ, JoyYDir, JoyType, JoyDown. |
Example
; JoyY Example ; ------------ Graphics 640,480,0,2 SetBuffer BackBuffer() While Not KeyDown(1) Cls ; JoyY returns the stick's y-axis as a float from -1.0 (full up) ; to 1.0 (full down); JoyX is its horizontal partner. jy#=JoyY() jx#=JoyX() If JoyType()=0 Then Text 0,0,"Esc: exit" Text 0,60,"No joystick detected - plug in a gamepad to try this example." Text 0,80,"With one attached, the crosshair below follows the stick." Else Text 0,0,"Move the stick up and down Esc: exit" End If ; Crosshair driven by the stick (sits centred with no input) x=320+jx*220 y=240+jy*180 Color 90,90,90 Line 0,y,639,y ; horizontal marker tracks the JoyY value Color 255,255,0 Oval x-10,y-10,20,20,False Line x-14,y,x+14,y Line x,y-14,x,y+14 Color 255,255,255 Text 0,20,"JoyY() = "+jy Text 0,40,"JoyX() = "+jx Flip Wend End
Index