AXIS: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_AXIS}} The _AXIS function returns the relative position of a specified axis number on a controller device. {{PageSyntax}} : {{Parameter|move!}} = _AXIS({{Parameter|axis_number%}}) * SINGLE values returned range between -1 and 1 as maximums and 0 indicating minimum or axis center. * When the mouse is moved on the program screen, moves left or above center are negative while below or right are positive. * The ''axis_number'' must be a number...")
 
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 7: Line 7:




{{PageDescription}}
* [[SINGLE]] values returned range between -1 and 1 as maximums and 0 indicating minimum or axis center.
* [[SINGLE]] values returned range between -1 and 1 as maximums and 0 indicating minimum or axis center.
* When the mouse is moved on the program screen, moves left or above center are negative while below or right are positive.
* When the mouse is moved on the program screen, moves left or above center are negative while below or right are positive.
Line 15: Line 16:
{{PageExamples}}
{{PageExamples}}
''Example:'' Reading multiple controller device buttons, axis and wheels.
''Example:'' Reading multiple controller device buttons, axis and wheels.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|_DEVICES}}
{{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_DEVICES}}
  {{Cl|PRINT}} {{Cl|STR$}}(i) + ") " + {{Cl|_DEVICE$}}(i) + " Buttons:"; {{Cl|_LASTBUTTON}}(i); ",Axis:"; {{Cl|_LASTAXIS}}(i); ",Wheel:"; {{Cl|_LASTWHEEL}}(i)
    {{Cl|PRINT}} {{Cl|STR$}}(i) + {{Text|<nowiki>") "</nowiki>|#FFB100}} + {{Cl|_DEVICE$}}(i) + {{Text|<nowiki>" Buttons:"</nowiki>|#FFB100}}; {{Cl|_LASTBUTTON}}(i); {{Text|<nowiki>",Axis:"</nowiki>|#FFB100}}; {{Cl|_LASTAXIS}}(i); {{Text|<nowiki>",Wheel:"</nowiki>|#FFB100}}; {{Cl|_LASTWHEEL}}(i)
{{Cl|NEXT}}
{{Cl|NEXT}}


{{Cl|DO...LOOP|DO}}
{{Cl|DO}}
  d& = {{Cl|_DEVICEINPUT}}
    d& = {{Cl|_DEVICEINPUT}}
  {{Cl|IF...THEN|IF}} d& {{Cl|THEN}} '            the device number cannot be zero!
    {{Cl|IF}} d& {{Cl|THEN}} {{Text|<nowiki>'            the device number cannot be zero!</nowiki>|#919191}}
    {{Cl|PRINT}} "Found"; d&;
        {{Cl|PRINT}} {{Text|<nowiki>"Found"</nowiki>|#FFB100}}; d&;
    {{Cl|FOR...NEXT|FOR}} b = 1 {{Cl|TO}} {{Cl|_LASTBUTTON}}(d&)
        {{Cl|FOR}} b = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTBUTTON}}(d&)
      {{Cl|PRINT}} {{Cl|_BUTTONCHANGE}}(b); {{Cl|_BUTTON}}(b);
            {{Cl|PRINT}} {{Cl|_BUTTONCHANGE}}(b); {{Cl|_BUTTON}}(b);
    {{Cl|NEXT}}
        {{Cl|NEXT}}
    {{Cl|FOR...NEXT|FOR}} a = 1 {{Cl|TO}} {{Cl|_LASTAXIS}}(d&)
        {{Cl|FOR}} a = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTAXIS}}(d&)
      {{Cl|PRINT}} {{Cl|_AXIS}}(a);
            {{Cl|PRINT}} {{Cl|_AXIS}}(a);
    {{Cl|NEXT}}
        {{Cl|NEXT}}
    {{Cl|FOR...NEXT|FOR}} w = 1 {{Cl|TO}} {{Cl|_LASTWHEEL}}(d&)
        {{Cl|FOR}} w = {{Text|1|#F580B1}} {{Cl|TO}} {{Cl|_LASTWHEEL}}(d&)
      {{Cl|PRINT}} {{Cl|_WHEEL}}(w);
            {{Cl|PRINT}} {{Cl|_WHEEL}}(w);
    {{Cl|NEXT}}
        {{Cl|NEXT}}
    {{Cl|PRINT}}
        {{Cl|PRINT}}
  {{Cl|END IF}}
    {{Cl|END IF}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) 'escape key exit
{{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}({{Text|27|#F580B1}}) {{Text|<nowiki>'escape key exit</nowiki>|#919191}}


{{Cl|END}} '' ''
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
: ''Note:'' When there is no device control to read, a [[FOR...NEXT|FOR]] n = 1 TO 0 loop will not run thus avoiding a control function read error.
: ''Note:'' When there is no device control to read, a [[FOR...NEXT|FOR]] n = 1 TO 0 loop will not run thus avoiding a control function read error.
Line 46: Line 47:
* [[_WHEEL]], [[_BUTTON]], [[_BUTTONCHANGE]]
* [[_WHEEL]], [[_BUTTON]], [[_BUTTONCHANGE]]
* [[_DEVICE$]], [[_DEVICES]]
* [[_DEVICE$]], [[_DEVICES]]
* [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]] {{text|(relative movement)}}
* [[_MOUSEMOVEMENTX]], [[_MOUSEMOVEMENTY]] {{Text|(relative movement)}}
* [[Controller Devices]]
* [[Controller Devices]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 14:22, 19 March 2023

The _AXIS function returns the relative position of a specified axis number on a controller device.


Syntax

move! = _AXIS(axis_number%)


Description

  • SINGLE values returned range between -1 and 1 as maximums and 0 indicating minimum or axis center.
  • When the mouse is moved on the program screen, moves left or above center are negative while below or right are positive.
  • The axis_number must be a number which does not exceed the number of axis found by the _LASTAXIS function.
  • The number of _DEVICES must be read before using _DEVICE$, _DEVICEINPUT or _LASTAXIS.


Examples

Example: Reading multiple controller device buttons, axis and wheels.

FOR i = 1 TO _DEVICES
    PRINT STR$(i) + ") " + _DEVICE$(i) + " Buttons:"; _LASTBUTTON(i); ",Axis:"; _LASTAXIS(i); ",Wheel:"; _LASTWHEEL(i)
NEXT

DO
    d& = _DEVICEINPUT
    IF d& THEN '             the device number cannot be zero!
        PRINT "Found"; d&;
        FOR b = 1 TO _LASTBUTTON(d&)
            PRINT _BUTTONCHANGE(b); _BUTTON(b);
        NEXT
        FOR a = 1 TO _LASTAXIS(d&)
            PRINT _AXIS(a);
        NEXT
        FOR w = 1 TO _LASTWHEEL(d&)
            PRINT _WHEEL(w);
        NEXT
        PRINT
    END IF
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit

END
Note: When there is no device control to read, a FOR n = 1 TO 0 loop will not run thus avoiding a control function read error.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link