Difference between revisions of "Key.axis"

From MiniScript Wiki
Jump to navigation Jump to search
(→‎Arguments: +smoothed param)
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
<c>key.axis</c> returns the numeric value (from -1 to 1) of an input axis.
+
<c>[[key]].axis</c> returns the numeric value (from -1 to 1) of an input axis (for example, a joystick horizontal or vertical axis).
  
See also: [[key.pressed]]
+
See also: [[key.pressed]]; [[How to move a sprite with directional inputs]]
  
 
=== Arguments ===
 
=== Arguments ===
Line 10: Line 10:
 
|-
 
|-
 
| ''axisName'' || string || Horizontal || name of axis to get
 
| ''axisName'' || string || Horizontal || name of axis to get
|}  
+
|-
 +
| ''smoothed'' || boolean || 1 || if true, return smoothed values to make the input a little more joystick-like; otherwise, return either <c>-1</c>, <c>0</c> or <c>1</c>
 +
|}
  
 
=== Usage Notes ===
 
=== Usage Notes ===
 
Available axis names are:
 
Available axis names are:
* "Horizontal" and "Vertical", which can be activated
+
* "Horizontal" and "Vertical", which can be activated by both WASD and arrow keys as well as any joystick or gamepad
by both WASD and arrow keys as well as any joystick or gamepad
+
* "Mouse X", "Mouse Y", and "Mouse ScrollWheel", which reflect movement/scrolling with the mouse
 
* "JoyAxis1" through "JoyAxis29" which detect axis inputs from any joystick or gamepad
 
* "JoyAxis1" through "JoyAxis29" which detect axis inputs from any joystick or gamepad
 
* "Joy1Axis1" through "Joy8Axis29" which detect axis inputs from specific joystick/gamepad 1 through 8.
 
* "Joy1Axis1" through "Joy8Axis29" which detect axis inputs from specific joystick/gamepad 1 through 8.
Line 22: Line 24:
  
 
<ms>print key.axis("Vertical")</ms>
 
<ms>print key.axis("Vertical")</ms>
 +
 +
A bigger example:
 +
 +
<ms>sp = new Sprite
 +
sp.image = file.loadImage("/sys/pics/Wumpus.png")
 +
display(4).sprites.push sp
 +
speed = 10  // pixels per frame
 +
while true
 +
sp.x = sp.x + key.axis("Horizontal") * speed
 +
sp.y = sp.y + key.axis("Vertical") * speed
 +
yield
 +
end while</ms>
  
 
[[Category:Mini Micro]]
 
[[Category:Mini Micro]]

Latest revision as of 15:39, 25 April 2024

key.axis returns the numeric value (from -1 to 1) of an input axis (for example, a joystick horizontal or vertical axis).

See also: key.pressed; How to move a sprite with directional inputs

Arguments

Parameter Name Type Default Value Meaning
axisName string Horizontal name of axis to get
smoothed boolean 1 if true, return smoothed values to make the input a little more joystick-like; otherwise, return either -1, 0 or 1

Usage Notes

Available axis names are:

  • "Horizontal" and "Vertical", which can be activated by both WASD and arrow keys as well as any joystick or gamepad
  • "Mouse X", "Mouse Y", and "Mouse ScrollWheel", which reflect movement/scrolling with the mouse
  • "JoyAxis1" through "JoyAxis29" which detect axis inputs from any joystick or gamepad
  • "Joy1Axis1" through "Joy8Axis29" which detect axis inputs from specific joystick/gamepad 1 through 8.

Example

print key.axis("Vertical")

A bigger example:

sp = new Sprite
sp.image = file.loadImage("/sys/pics/Wumpus.png")
display(4).sprites.push sp
speed = 10  // pixels per frame
while true
	sp.x = sp.x + key.axis("Horizontal") * speed
	sp.y = sp.y + key.axis("Vertical") * speed
	yield
end while