Skip to content

Joystick

Install

Please install the @canvasengine/presets package first.

bash
npm install @canvasengine/presets

Then, you can use the presets in your project.

Usage

html
<Canvas>
    <Joystick />
</Canvas>

<script>
    import { Joystick } from '@canvasengine/presets'
</script>

Properties

PropertyTypeDefaultDescription
outerstring-Path to the outer joystick image
innerstring-Path to the inner joystick image
outerScale{ x: number; y: number }Scale of the outer joystick element
innerScale{ x: number; y: number }Scale of the inner joystick element
onChange(data: JoystickChangeEvent) => void-Callback function triggered when joystick position changes
onStart() => void-Callback function triggered when joystick interaction starts
onEnd() => void-Callback function triggered when joystick interaction ends

And use all the properties of the Container component.

JoystickChangeEvent

The onChange callback receives a JoystickChangeEvent object with the following properties:

PropertyTypeDescription
xnumberX-axis position (-1 to 1)
ynumberY-axis position (-1 to 1)
anglenumberAngle in degrees (0-360)
distancenumberDistance from center (0-1)