by Jon (Updated on 2015-10-17)
Stencyl supports external controllers (such as gamepads) for Windows, Mac and Linux games. Standard controllers are supported, including popular models such as the Xbox and Playstation controllers.
Note: Controllers are not yet supported on Flash, HTML5, iOS and Android.
As you may recall from the Controls article, Stencyl doesn't encourage you to work directly with input devices.
In order to establish "controls" for a game, you set up Controls in the Game Settings editor and assign specific keys (such as up/down/left/right/Z/X) to those controls. That way, if you decide to change a control's key in the future, you only have to change that in one place, versus many.
It turns out that this setup makes gamepad support easier for you too. To support gamepads, you do the same thing - bind a key on your controller to a control.
Sounds simple enough, but to do this, you need to know what the names of the buttons are. They differ from device to device.
If you would like to build a controller mapping, you'll first need to figure out what the button ID's are for the controls for your game.
To do this, use the Gamepad event, located at Add Event > Input > Desktop-Only > Any Button. Then, print out the input like so.
Run a game with this behavior and take down the ID's (by pressing the button on your controller and observing the output in the Log Viewer).
For example, these are some of the IDs for an Xbox 360 controller. (We've added the names for your reference.)
Aside: The 0 that precedes each button ID corresponds to "controller 0" -- meaning that if multiple controllers are hooked up, this part can change depending on what's plugged in.
To build a mapping, use the map button block to establish that. (All Gamepad blocks are located under User Input > Gamepad)
What if a player wants to custom configure their controller?
See the next section.
Does Stencyl provide out-of-the-box support for common controllers like the XBox and PlayStation controllers?
Not at this time. If you've come up with some, upload them and share a link. We'll include them in future updates to this article.
What should I watch out for?
Players using a less common controller will need to manually configure their controller during the game. This typically involves running through each game control one by one, prompting them for a button press and then saving that out to a file.
We provide two blocks to assist with the saving/loading of configurations...
(Much like our save/load blocks, provide a filename in the lone blank. It doesn't really matter what you put in.)
This sample project demonstrates how accomplish what we described above -- namely, getting the user configure each game's control by pressing a button on their controller. We leave it to you to customize the look to fit your game's needs.
Analog Controls correspond to buttons on a controller that detect not just whether they are pressed down, but how much they are pressed down. This contrasts with Digital Controls, which can only detect whether they are down or not.
On most modern controllers, two kinds of buttons fall into this category.
In the case of a control stick, the stick detects how far it's tilted, so that a character walks quicker when it's tilted fully, versus halfway. As for the shoulder button, pressing the button down harder will be registered differently from pressing it down softer.
Stencyl provides two blocks for working with analog controls.
This block gets you the pressure (amount of tilt/press) for a given control as a value between 0 and 1, inclusive, where 0 means no tilt/press and 1 means full tilt/press.
Have you ever played a game and found the character walking by himself despite you not touching the controller?
This setting lets you set the sensitivity ("dead zone") for an analog control, so that lesser amounts of pressing/tilting don't get interpreted as actions. The default value is 0.
Provide a value between 0-100, inclusive, where 0 means that any amount of tilt/press will be detected and 100 effectively disables the button. We advise setting it between 10-25 and for games where this is critical, allowing the user to configure it to their liking.