Dragging Objects on Android

Sannyasin Brahmanathaswami brahma at hindu.org
Mon Sep 26 23:04:47 EDT 2016


Is anyone successfully setting up a UX where the user can drag objects around the screen that actually works on Android?
We invested a lot of time, thought and now $ for a developer to carry out the vision for a UX that uses "grab me" for tiles on screen … initially for  two small puzzle games, one a word/sentence scrabble and another an image puzzle. We have (had?) plans for other modules that use grab me. And this user interaction is pretty basic to a lot of touch/game interfaces. it's "so old" that I never imagined it could fail.
It works great on Desktop and on iOS, but to our dismay, when we tested on Android it failed so badly as to be a show stopper.
see:
http://quality.livecode.com/show_bug.cgi?id=18476
Jacque has a test stack there that we developed together… you can try…
The hard code was getting puzzle tiles made dynamically, (tks to Peter Brett's tip on cropping  a snapshot…) after that it is a simple matter to attach a behavior to each of the tiles (script below)  We tried following mouseMove instead of using grab me… but the performance is no better than grab me, on Android: basically unusable.
Any insights?
local sDragging
On MouseDown
# don't let user drag an image that was placed successfully:
if the uInPlace of me <> "true" then
set the layer of me to top
-- grab me
put true into sDragging
end if
end MouseDown
on mouseMove x,y
if not sDragging then exit mouseMove
set the loc of me to minMax(the rect of this cd)
glowtile me, word 1 of checkHomeProximity()
end mouseMove
function minMax pRect -- get a point within bounds
if pRect = "" then
put the rect of this card into pRect
end if
put max(item 1 of pRect,min(item 3 of pRect,the mouseh)) into x
put max(item 2 of pRect,min(item 4 of pRect,the mousev)) into y
return x,y
end minMax
on mouseUp
-- outOfFrame
put false into sDragging
put checkHomeProximity() into tIsHome
if word 1 of tIsHome = true then
set the loc of me to the uWordLocation of me
glowtile me, false
set the uInPlace of me to "true"
set the showborder of me to "false"
runpixie
end if
checkCompletion
end mouseUp
on mouseRelease
put false into sDragging
end mouseRelease
## We need to disallow dragging outside the bounds
## of the card:
command outOfFrame
put the rect of this card into tBounds
put the loc of me into tMyLoc
put tMyLoc into tStartLoc
switch
case ( (item 2 of tMyLoc) > (item 4 of tBounds) )
put (item 4 of tBounds -20) into tVaxis
put tVaxis into item 2 of tMyloc
put 1 into tOutOfBoundsFlag
break
case (item 2 of tMyLoc <0)
put 30 into item 2 of tMyloc
put 1 into tOutOfBoundsFlag
break
case ( (item 1 of tMyLoc) > (item 3 of tBounds) )
put item 3 of tBounds-20 into tHaxis
put tHaxis into item 1 of tMyLoc
put 1 into tOutOfBoundsFlag
break
case (item 1 of tMyLoc <0)
put 30 into item 1 of tMyloc
put 1 into tOutOfBoundsFlag
end switch
if tOutOfBoundsFlag = 1 then
set the loc of me to tMyLoc
put 0 into tOutOfBoundsFlat
end if
# MONITOR:
--put tStartLoc & cr & tMyLoc & cr & tBounds
end outOfFrame
function checkHomeProximity # Cause tile to snap to location if close
put the uWordLocation of me into tMyHome
put the abs of (item 1 of the loc of me - item 1 of tMyHome) into tLeftDistance
put the abs of (item 2 of the loc of me - item 2 of tMyHome) into tTopDistance
if (the abs of (item 1 of the loc of me - item 1 of tMyHome) < 20) AND \
(the abs of (item 2 of the loc of me - item 2 of tMyHome) <20) then
return "true"
end if
return false
end checkHomeProximity



More information about the use-livecode mailing list