Page 1 of 1

Best syntax for touch and drag

Posted: Tue Dec 13, 2011 2:37 am
by richardmac
I'm working on an app for very young children and I'm trying to put shapes on the screen that they can touch and drag, on the iPad. The syntax is simple enough ("grab me") but the performance has a lag that might not be good enough for very young children. I've been reading the documentation about coregraphics and opengl and accelerated rendering and all I did was confuse myself.

Anyone have any suggestions for the best way to do touch and drag for iPad, meaning the absolute fastest performance? I'm guessing and testing right now but I figured I'd ask in case someone has already walked down this path. Thanks in advance!

Re: Best syntax for touch and drag

Posted: Tue Dec 13, 2011 2:06 pm
by Mark
Hi,

Currently, I use mouseStilldown, because repeat until mouseUp didn't work in a previous version of LiveCode. MouseStillDown may show a bit of a lag, but the image is unable to lose track of my finger. An advantage is that it doesn't lock up the interface, i.e. you can still show a field with changing "mouse" coordinates e.g.

Generally, the fastest way is to use a simple repeat loop, which does lock up the interface, but this may drain your battery:

Code: Select all

repeat while the mouse is down
  set the loc of me to the mouseLoc
end repeat
Note that the mouseUp message will not be fired after this repeat loop.

You may also try touchMove, which was added to the syntax specifically for mobile platforms. This might be the quickest way:

Code: Select all

on touchMove theObjectID,theX,theY
  set the loc of control id theObjectID to theX,theY
end touchMove
The examples in this reply are just very simple examples that show how the syntax works but you may need to change the scripts to make them work for you.

Kind regards,

Mark

Re: Best syntax for touch and drag

Posted: Tue Dec 13, 2011 8:38 pm
by jacque
Accelerated rendering is now pretty much automatic in today's release of 5.0.2. You only need to set a stack property. The same is true for dynamic object rendering -- you used to have to specify that in a script for every object, but now those are also object properties. So for your app, just set the dynamic rendering of all draggable objects, click on the stack accelerated rendering property, and you should be good.

If you are using an older version of Rev, performance will suffer because there is no accelerated rendering available. However, instead of grab, I'd use a mousemove message and a couple of script local variable flags to track which object is being moved and whether or not the mouse is down. Mousemove will be faster than a repeat loop and won't lock up the app.

Re: Best syntax for touch and drag

Posted: Tue Dec 13, 2011 9:59 pm
by richardmac
jacque wrote:Accelerated rendering is now pretty much automatic in today's release of 5.0.2. You only need to set a stack property. The same is true for dynamic object rendering -- you used to have to specify that in a script for every object, but now those are also object properties. So for your app, just set the dynamic rendering of all draggable objects, click on the stack accelerated rendering property, and you should be good.

If you are using an older version of Rev, performance will suffer because there is no accelerated rendering available. However, instead of grab, I'd use a mousemove message and a couple of script local variable flags to track which object is being moved and whether or not the mouse is down. Mousemove will be faster than a repeat loop and won't lock up the app.
Thanks for the tip - Just played with it, and mousemove does appear to be the fastest thing going for doing this on the iPad. Works very well - thanks!

I think I used to be on the same HyperCard mailing list as you, way back in the day. And your cgi tutorial for using MetaCard was my guide for all the cgi work I did at my last school. Glad to see you in here!

Re: Best syntax for touch and drag

Posted: Tue Dec 13, 2011 10:53 pm
by jacque
How cool. A lot of us old HyperCarders ended up here, it's a natural progression. Glad to see you here too!