Joystick control simulator
A joystick object creates a virtual touch area of the screen which automatically tracks a users touch movements. When you create a joystick you
specify a center location for the stick. You may also provide a sprite that follows the user's touch movements.
Joysticks in absolute mode have a radius around their
centers inside which touches are registered. Once a touch is detected within a joystick's radius, an event is fired for which are routine can read
various joystick parameters.
In absolute mode, joystick position values are relative to the center positions of the joystick. In the other mode, relative, the
position values are relative to the last position of the joystick.
Joystick event values give position and angles of the joysticks position via a _joy variable.
Details below.
- active=[true|false]
- whether or not joystick is currently active
- center={number,number}
- the location of the joystick on screen
- mode=[relative|absolute]
- relative (default) or absolute. Indicates if _joy expression values are relative to the last stick position or to the center of the joystick.
- move={routine name}
- the routine to run when the joystick is moved (touched and moved within the specified radius)
create routine as OnJoyStick
if (_joy.direction=="up")
update var NewManDir set=1
elsif (_joy.direction=="right")
update var NewManDir set=2
elsif (_joy.direction=="down")
update var NewManDir set=4
elsif (_joy.direction=="left")
update var NewManDir set=8
endif
if (_joy.compass=="nw") Whatever() endif
end
- radius={number}
- radius for detecting a touch on the joystick when mode is absolute.
- sprite={sprite name}
- a sprite to move with the drag of the joystick.
The routine called by 'move' will have access to the values below. They can be accessed as _joy.angle
- _joy.angle
-
Angles are based on the unit circle where up is 90° and towards the right is 0°
- Absolute Mode: the angle of this position compared to joystick's center position
- Relative Mode: the angle of this position compared to the last joystick position
- _joy.distance
-
the distance of the joystick's current position to the joystick's center position
- _joy.x
- the canvas x position of the touch
- _joy.y
- the canvas y position of the touch
- _joy.deltax
- the change in x position since last touch movement
- _joy.deltay
- the change in y position since last touch movement
- _joy.percent
- the percentage of the distance from the center of the joystick to the radius for the joystick
- _joy.direction
- doubled-quoted: up, down, left or right
- _joy.compass
- doubled-quoted: n,ne,e,se,s,sw,w, or nw
- _joy.moved
- the distance the stick moved since its last position