by Jon (Updated on 2015-10-14)
Mobile apps are driven by touching, tapping and other gestures. Stencyl exposes all of these features through a combination of events and blocks.
Single-touch is handled using the mouse blocks. In other words, treat touch just like using the mouse.
Mouse Action | Touch Action |
---|---|
Mouse is Down | Touching Screen |
Mouse is Down on Actor | Touching Actor |
X of Mouse | X of Touch |
Y of Mouse | Y of Touch |
If you prefer to use Events, the analogous Mouse Events do the same thing.
For many games, single-touch is sufficient, but for some games, it’s necessary to support multi-touch. Such games require tracking several fingers on screen moving independently. One very common example of this use case is a game that displays multiple on-screen buttons, such as a platformer.
Stencyl supports multi-touch exclusively through an event.
This event is triggered any time a touch begins, is dragged around or ends. Using the ID of touch block, which maintains the same value throughout the lifecycle of a touch, you can refer to that touch and act accordingly.
Additionally, you'll find that the ID of touch block also lets you get the X/Y positions of that particular touch by selecting those options from its dropdown.
You must enable multi-touch in Settings > Mobile > User Input to receive multi-touch events. Moreover, when multi-touch is enabled, avoid using single-touch input blocks, for they will act in unexpected ways.
In other words, when multi-touch is enabled, count on using multi-touch blocks all the way through.
In this example, the player can move some objects independently of each other using multi-touch.
Tip: Are you just looking to implement virtual, on-screen buttons? Grab the On Screen Button behavior from StencylForge, which uses multi-touch in its implementation.
Swiping is a gesture in which the player presses a finger on screen and drags it in one direction. It is commonly used to scroll through menus or trigger certain actions.
In Stencyl, the preferred way to detect a swipe is through a Swipe event, accessed via Add Event > Input > Swipe.
If you prefer to use a block to check for this instead, you can find one under User Input > Mobile-Only.