Humanities Home page   Office of Digital Humanities
Back     BYU LiveCode Lessons Gateway

Touch Screen Gestures in LiveCode

LiveCode is designed to make it relatively simple to create interfaces that will work on both mouse-based desktop platforms and touch screen mobiles devices. This is acheived primarily by simply mapping mouse messages to corresponding touch actions on mobile platforms. There are a few considerations to keep in mind, however, which are summarized here.

Touch Messages

There is a whole complement of touch messages that correspond to mouse messages; e.g.:

touchStart mouseDown
touchMove mouseMove
touchRelease mouseRelease

In practice, it seems that many LiveCode developers prefer to simply use the mouse messages and rely on the LiveCode engine to process them properly in the mobile environment. Here's a quote from a message by Jacqueline Landman Gay on the Use-LiveCode mail list:

I used to do it your way -- passing touch messages to mouse messages after checking the environment. When we were writing the teaching stack for the conference, Mark Waddingham [RunRev CTO] suggested we just ditch the touch messages entirely and use only mouse messages. I've been doing that ever since, it works fine. Touch messages are passed to mouse messages automatically, so eliminating them also removes an extra message from the hierarchy and avoids the problem of double messages entirely.

I've seen no differences in response times using only mouse messages.

For more on the touch messages, see LiveCode's Mobile Specific Engine Features article, under the heading "Multi-touch events".

Swipe Gestures

Here is some sample code for a swipe motion to move between cards:

on mouseDown
   put the mouseH into sStartH
end mouseDown

on mouseUp
   if abs(the mouseH - sStartH) > 50 then
      if the mouseH < sStartH then
      end if
   end if
end mouseUp

command goNext
   lock screen for visual effect
   go to next card
   unlock screen with visual effect push left
end goNext

command goPrev
   lock screen for visual effect
   go to prev card
   unlock screen with visual effect push right
end goPrev

Shake Motion

There are three messages provided for handling device motion:

motionStart motionType

motionEnd motionType

motionRelease motionType

From the Release Notes for iOS and Android:

At present, the only motion that is generated is "shake". When the motion starts, the current card of the defaultStack will receive motionStart and when the motion ends it will receive motionEnd. In the same vein as the touch events, motionRelease is sent instead of motionEnd if an event occurs that interrupts the motion (such as a phone call).

Here is a simple handler demonstrating how you could handle a shake motion:

on motionEnd pMotion
   if pMotion is "shake" then
      cleanup # i.e., call a handler that performs the desired action
   end if
end motionEnd

For more on motion messages, see LiveCode's article on Mobile Specific Engine Features, under the heading "Motion Events".

Back     BYU LiveCode Lessons Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University