31,621

Views

Beginner

Level

7

Comments

Mobile Input - Touch & Gestures

by Jon (Updated on 2015-10-14)


Contents

  • Introduction
  • Single Touch
  • Multi-Touch
  • Example: Multi-Touch
  • Swiping
  • Example: Swiping

Introduction

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

Using Blocks

Single-touch is handled using the mouse blocks. In other words, treat touch just like using the mouse.

mouse-blocks

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

Using Events

If you prefer to use Events, the analogous Mouse Events do the same thing.

mouse-events

Multi-Touch

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.

multitouch-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.

position-of-touch

Warning: Do Not Mix Single and Multi-Touch

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.

Example: Multi-Touch

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

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.

swipe

Swipe Event

In Stencyl, the preferred way to detect a swipe is through a Swipe event, accessed via Add Event > Input > Swipe.

swipe-event swipe-event

Swipe Block

If you prefer to use a block to check for this instead, you can find one under User Input > Mobile-Only.

swipe-block

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

7 Comments

theigloo
dose anyone know where i can learn to do multi touch so i can run and jump at the same time on mobile?
2 1 year, 9 months ago
jrandiny
@yoplalala it's not recommended and may cause PROBLEMS but yes, you can mix single touch and multi touch
0 1 year, 11 months ago
yoplalala
"In other words, when multi-touch is enabled, count on using multi-touch blocks all the way through."

can we use single touchs in some scenes and multi-touche in some other scenes ?

0 1 year, 12 months ago
djngam
my touch sreen function doesnt work even though i used the universal mouse click really stumped on what to do. help! thanks!
0 3 years, 1 month ago
Slimefon
Don't understand the multi touch part one bit, the explanation is very vague. Help!
2 3 years, 4 months ago
Karutobi
Download demo for multi-touch is not available. Directs me to a blank page...
0 3 years, 6 months ago
rogerrenno
This is amazing!!!!
-1 3 years, 7 months ago

Sign In to Comment