Mobile Input

Monkey Targets Forums/HTML5/Mobile Input

MarkSponge(Posted 2012) [#1]
What is the best way to handle input for HTML5 on a mobile device? I have found that iOS and android behave the same way, in which a MouseHit() call is being recognised but the MouseX and MouseY value don't update unless you move your finger on the canvas.

This means that to press a button I cannot simple press it, I need to drag my finger onto it, then release.

How would I get the mouse position of a MouseHit when the MouseX and MouseY values are wrong?


NoOdle(Posted 2012) [#2]
I normally use TouchX and TouchY, this is handled by HTML5 and converted to mouse. Have you tried this way round? It might fix your problem - it should register the x and y as soon as you touch the screen. The code below has not been tested but it should work (ive used similar).
If TouchHit()
    If PointInsideRect( TouchX(), TouchY(), x1, y1, x2, y2 )
         'do stuff
    endif
endif

Function PointInsideRect : bool( px : float, py : float, x1 : float, y1 : float, x2 : float, y2 : float )
    if px > x1 and py < x2
        if py > y1 and py < y2
            return True
        endif
    endif
    return False
end function



MarkSponge(Posted 2012) [#3]
Thank's NoOdle. That did it. I feel like a moron.