Using the Joystick
by Jon (Updated on 2014-01-30)
- Showing the Joystick
- Changing the Appearance
- Changing the Mode
Some games involve moving a character around freely. Often, these games require a joystick to provide precise-enough control over that character’s movements.
Creating the logic yourself that would allow joystick input would be cumbersome. Thankfully, we’ve built this functionality into Stencyl.
Showing the Joystick
To enable the joystick and access its values, use the blocks shown below. They’re located under the User Input > Mobile category.
Joystick direction ranges from 0 to 360 degrees, inclusive.
Joystick distance equals how far the user has “stretched” the joystick relative to its center, in pixels.
The following example code, used in the Joystick example game, shows how to use the blocks to implement player movement.
Don’t panic about the math - you can find this behavior as part of your local Library when importing a behavior (From Your Library > Mobile > Joystick).
You can adjust the “-10” values shown next to the joystick distance block to tune the sensitivity and movement to your liking.
Changing the Joystick's Appearance
You can change the Joystick’s appearance and how it appears on the screen through the Settings > Mobile > Joystick page.
Access the Joystick Configuration Page
Click the Settings button, as shown, to open the dialog:
Next, click Mobile > User Input, as shown in #1 and #2.
Changing the Appearance involves providing two graphics - one for the "background" and one for the moveable portion of the josytick.
Changing the Mode
You have full control over when and where the joystick appears on the screen using blocks under User Input > Mobile category.
The Show where Pressed option shows the joystick where the user last touched the screen. This is the default.
The Fixed option shows the joystick at a fixed position on screen. To set this position, use the following block, located under the User Input > Mobile category.
Are dual joysticks supported?
In Stencyl 3.0 and above, dual joysticks are supported. As the name suggests, dual joysticks let you work with two joysticks rather than one. All of the key joystick operations can now be applied to Joystick 1, Joystick 2 or both of them.
Can I hide the joystick but still have it work?
You can "hide" the joystick but still have it work by importing blank graphics.