HTML5: MouseX/Y()not updated on touch devices

Monkey Forums/Monkey Bug Reports/HTML5: MouseX/Y()not updated on touch devices

Alain(Posted 2012) [#1]
There is a small bug when running HTML5 applications on touch devices: If user do not move the finger, the MouseX(), MouseY() functions are not updated.

Example code:
Import mojo

Class Test Extends App
	
	Method OnCreate()
		SetUpdateRate 60
	End
	
	
	Method OnUpdate()		
	End

	Method OnRender()	
		Cls 0,0,128
		If(MouseDown())
			SetColor 128,0,255
		Else
			SetColor 128,255,0
		Endif		
		DrawOval MouseX(),MouseY(),32,32
		
	End
End

Function Main()
	New Test
End


If you are running this code on a touch device and just touch the screen without moving, you'll see the oval on the wrong place.

** Correction **

I changed the following on the generated code to fix the problem:

gxtkInput.prototype.OnTouchMove=function( id,x,y ){
	for( var i=0;i<32;++i ){
		if( this.touchIds[i]==id ){
			this.touchXs[i]=x;
			this.touchYs[i]=y;
			if( i==0 ){                  // ADD THESE LINES
				this.mouseX=x;       //
				this.mouseY=y;       //
			}                            //
			return;
		}
	}
}


Hope it helps!


Richard(Posted 2012) [#2]
This helped me finding another issue.

The issue is that OnTouchStart is not giving the right x & y.
The effect is that when you move over a certain area and "click" it works, but not the first time without moving.

This fixes it for me:
gxtkInput.prototype.OnTouchStart=function( id,x,y ){
	for( var i=0;i<32;++i ){
		if( this.touchIds[i]==-1 ){
			this.touchIds[i]=id;
			this.touchXs[i]=x;
			this.touchYs[i]=y;
			this.OnKeyDown( KEY_TOUCH0+i );
                        this.OnTouchMove(id,x,y);       // Added this line
			return;
		} 
	}
}