As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

48,834

Views

Beginner

Level

9

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!

9 Comments

LenseOnLife
I've done 2 tutorials on the MultiTouch Mobile Input Block which might help some people come to grips with the subject. They can be found at:

https://youtu.be/icEhKmu6uiI
https://youtu.be/EMu2q7eQMQE

Oliver

0 6 years, 9 months ago
BMJ
IMPORTANT UPDATE NEEDED: The "On Screen Buttons" behavior this article recommends needs to be updated to work with newer versions if Stencyl, otherwise it will crash the game, because the list attribute "Touching IDs" is not initialized as "create new list".

Until that's resolved, what you need to do to make this behavior work is add the following blocks in the 'created' event of the "on Screen Buttons" behavior:

Set [Touching IDs] to [create new list]

The "create new list" block is under attributes ---> lists in the pallete.

0 6 years, 10 months ago
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 8 years, 11 months ago
jrandiny
@yoplalala it's not recommended and may cause PROBLEMS but yes, you can mix single touch and multi touch
0 9 years, 1 month 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 9 years, 1 month 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 10 years, 3 months ago
Slimefon
Don't understand the multi touch part one bit, the explanation is very vague. Help!
2 10 years, 6 months ago
Karutobi
Download demo for multi-touch is not available. Directs me to a blank page...
0 10 years, 8 months ago
rogerrenno
This is amazing!!!!
-1 10 years, 9 months ago

Sign In to Comment