Level: Beginner
Using the Joystick
Contents
-
Introduction
-
Showing the Joystick
-
Changing the Joystick's Appearance
-
Joystick Behavior
-
Dual Joysticks
Introduction
Some games involve moving a character around in a wide range of directions. 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, and it just takes a couple of steps to enable it!
How to Enable and Use 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.
Example
The following example code, used in the Joystick example game, shows how to use the blocks to implement 360-degree player movement.
Don’t panic about the math - you can find this behavior on StencylForge by searching for “Joystick” or 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 is a matter of providing two graphics - one for the "background" and one for the moveable portion of the josytick.
Tip: Don't want to display the joystick at all? Provide blank graphics.
Changing the Behavior
Note: In Stencyl 3.0, joystick behavior is controlled through a block under User Input > Mobile.
You have full control over when and where the joystick appears on the screen. In Stencyl 2.2, this is on the same page where you provided the graphics. In Stencyl 3.0, these are exclusively controlled through blocks under User Input > Mobile.
The Show where Pressed option shows the joystick where the user last touched the screen.
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.

Dual Joysticks
Note: Dual Joysticks are available in Stencyl 3.0 and above.
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 or both of them.
[TODO: Dual joystick motion example]
Last Updated: 2013-04-10 by Jon
7702 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game,
please ask a question on the forums. Thanks!
Sign In to Comment