User Input > Joystick


Read our guide on Joysticks before consulting this reference.


Joystick

Add a Static Joystick

create static joystick int at x number y number

Adds a new static joystick to the screen at the given coordinates. A static joystick works only if you touch or click inside its outer radius. Other touches or clicks outside its outer radius will be ignored. Static doesn't mean immovable: you can move a static joystick by using the set center for joystick block.

Joystick.addJoystick([INT], [NUMBER], [NUMBER], 0, 0, 0, 0, 0, false);

Add a Relative Joystick

create relative joystick int at x number y number with touch region x number y number w number h number

Adds a new relative joystick to the screen. For a relative joystick its center position is relative to the coordinates of mouse or touch first press. A relative joystick works only inside its own touch region.

Joystick.addJoystick([INT], [NUMBER], [NUMBER], 1, [NUMBER], [NUMBER], [NUMBER], [NUMBER], false);

Remove a Joystick

remove joystick int

Removes a joystick from the screen.

Joystick.removeJoystick([INT]);

Default Direction

set default direction to number in degrees for joystick int

The direction of the joystick will be set to this default direction when the joystick is idle.

Useful when you want an actor to face towards a particular direction when the player doesn't press the joystick. The default value of default direction is 0.

Joystick.setDefaultDirection([INT], [NUMBER]);

Set Radius

set outer radius to number for joystick int

Sets the inner or the outer radius to a given value for a joystick.

The default value of the outer radius is half the width of the outer joystick. The default value of the inner radius is half the width of the inner joystick.

Joystick.setJoystickRadius([INT], true, [NUMBER]); //outer joystick
Joystick.setJoystickRadius([INT], false, [NUMBER]); //inner joystick

Set Touch Region (for a Relative Joystick)

set touch region to x number y number w number h number for relative joystick int

Sets the x position, y position, the width and the height of the touch region of a joystick. You can use this block to update the position and/or the size of a touch region of an existing relative joystick.

Joystick.setTouchRegionForRJ([INT], [NUMBER], [NUMBER], [NUMBER], [NUMBER]);

Set Center Coordinates

set center to x number y number for joystick int

Sets the center position of a joystick.

Joystick.setJoystickCenter([INT], [NUMBER], [NUMBER]);

Set Joystick Images

set image to text for outer joystick int

Sets the image of the outer or inner part of a joystick. You need to have corresponding images inside your games "extras" folder, one for each scale:

imagename.png
imagename@1.5x.png
imagename@2x.png
imagename@3x.png
imagename@4x.png
Joystick.setJoystickImage([INT], true, [TEXT]); //outer joystick
Joystick.setJoystickImage([INT], false, [TEXT]); //inner joystick

Set Joystick Transparency

set opacity to number for released outer joystick int

Sets the joystick image transparency for a joystick.

Joystick.setJoystickAlpha([INT], true, [NUMBER], true); //outer joystick when released
Joystick.setJoystickAlpha([INT], true, [NUMBER], false); //outer joystick when pressed
Joystick.setJoystickAlpha([INT], false, [NUMBER], true); //inner joystick when released
Joystick.setJoystickAlpha([INT], false, [NUMBER], false); //inner joystick when pressed

Auto-hide a Joystick

always hide joystick int when touch or mouse is released

Makes a relative joystick to be always hidden when it is idle. Since the position of a relative joystick is not so important, you can use this block to always hide a relative joystick id when there is no press to save some screen space.

Joystick.alwaysHideRJ([INT]);

Joystick is Pressed

joystick int is pressed

Returns 'true' if the joystick is being pressed, 'false' otherwise.

Joystick.isJoystickPressed([INT])

Distance / Direction

direction of joystick int

Returns the distance or the direction of a joystick.

Distance is always a float number between 0 and 1. Direction is always a float number between 0 (inclusive) and 360 (exclusive), where 0 means that the joystick is facing towards right, and 90 means that the joystick is facing down.

Joystick.getJoystickDisDir([INT], false) //direction
Joystick.getJoystickDisDir([INT], true) //distance

Jostick Center Coordinates

x center of joystick int

Returns the x or the y coordinate of the center of a joystick.

Joystick.getJoystickCenter([INT], true) //x
Joystick.getJoystickCenter([INT], false) //y

Joystick Radius

outer radius of joystick int

Returns the outer or inner radius value for a joystick.

Joystick.getJoystickRadius([INT], true) //outer joystick
Joystick.getJoystickRadius([INT], false) //inner joystick

Touch Region (for a Relative Joystick)

touch region x for relative joystick int

Returns the position or size of the touch region for a relative joystick.

Joystick.getTouchRegionPropertyForRJ([INT], 1) //x
Joystick.getTouchRegionPropertyForRJ([INT], 2) //y
Joystick.getTouchRegionPropertyForRJ([INT], 3) //width
Joystick.getTouchRegionPropertyForRJ([INT], 4) //height