Drag and release problem! Rgghhhh!!!

Monkey Forums/Monkey Programming/Drag and release problem! Rgghhhh!!!

DruggedBunny(Posted 2012) [#1]
OK, this has got me totally stumped, despite seeming like a really simple problem.

The code below (a crude sort of calendar display) shows the behaviour I want -- you can drag across the screen and the view will follow, then it slows to a stop upon release, so you can basically 'fling' the view... at least, this happens when using a mouse on the PC targets.

However, switch to Android and it fails, because each time you touch the screen you cause the mouse position to 'jump' to the new touch point (whereas the mouse position is constantly tracked on PC).

I can simulate this on PC by putting the MouseX code after MouseDown -- disable the "Version 1" code below and enable the "Version 2" code -- but for the life of me cannot figure out how to account for the jump!

I've tried storing the last-known position before release and subtracting from the new MouseX, fiddling with lastmx, chanting to the rain gods, etc, etc, but nothing I've tried works and it's driving me crazy!

Can anyone see how to solve what is no doubt a really simple problem, before I go on a machine-gun rampage through the streets?! (I should point out that it would be an imaginary machine-gun, which would arguably be an even sorrier sight.)




Jesse(Posted 2012) [#2]
I believe this one works good on TouchScreens(UNTESTED):


[EDITED FOR SIMPLIFICATION]


muddy_shoes(Posted 2012) [#3]
You just need to avoid setting lastmx to be the value left from the last time the user touched the screen. For example:

[monkeycode]
If MouseDown (0)

mx = MouseX()

'if this is the start of a drag init lastmx to be the same as mx
If lastmx = -1
lastmx = mx
End

offsetspeed = mx - lastmx

lastmx = mx

Else
'reset lastmx
lastmx = -1

offsetspeed = offsetspeed * 0.9
If Abs (offsetspeed) < 0.01 Then offsetspeed = 0
End
[/monkeycode]


DruggedBunny(Posted 2012) [#4]
Brilliant, thanks guys... think I might have been over-complicating the problem but glad to have a fix!


Samah(Posted 2012) [#5]
If you're using the Diddy framework there's automatic handling of fling events in the Screen class. I think the method to override is called OnTouchFling.


Supertino(Posted 2012) [#6]
Hey Drugged bunny sorry to hijack this thread but are you planning to update your delightful autofit mod for the new read/write pixel stuff? I managed to fudge in some code to suit my requirements - though it's not elegant.


DruggedBunny(Posted 2012) [#7]
Dunno, haven't got around to playing with it yet... what's the problem you're having? I'm guessing that ReadPixel'ing from 0,0 includes part of the border or something like that?


Supertino(Posted 2012) [#8]
Yeah, also need to account for scaling when reading pixels - easy enough to fix though.