Autofit and buttons

Monkey Forums/Monkey Programming/Autofit and buttons

TheMrCerebro(Posted 2014) [#1]
I am trying to create the touch menu for a game in android and i am using "autofit" to automatically adjust to the resolution.

The problem I have is when a region is pressed in a position (posx: 10 posy: 20 width: 32 height: 32) is not pressed correctly.

My code:
Function TouchRegion:Bool(x:Float,y:Float,w:Float,h:Float,hit:bool)
	
	For Local i=0 Until 3

		If (x <= VTouchX(i) And y <= VTouchY(i) And x+w >= VTouchX(i) And y+h >= VTouchY(i)) Then
			If hit then
				If TouchHit(i) Then Return True
			Else
				If TouchDown(i) Then Return True
			endif
		Endif
	
	Next
	
	Return False
	
end


Autofit (with VTouch):
Method VTouchX:Float(index:int)
		
	' Position of mouse, in real pixels, from centre of screen (centre being 0)...
	Local touchoffset:Float = TouchX(index) - Float (DeviceWidth) * 0.5
		
	' This calculates the scaled position on the virtual display. Somehow...
	Return (touchoffset / multi) / vzoom + (VDeviceWidth * 0.5)

End

Method VTouchY:Float(index:int)
	
	' Position of mouse, in real pixels, from centre of screen (centre being 0)...
	Local touchoffset:Float = TouchY(index) - Float (DeviceHeight) * 0.5
		
	' This calculates the scaled position on the virtual display. Somehow...
	Return (touchoffset / multi) / vzoom + (VDeviceHeight * 0.5)
		
End



rIKmAN(Posted 2014) [#2]
Are you using SetVirtualDisplay in OnCreate() and UpdateVirtualDisplay in OnRender()?


TheMrCerebro(Posted 2014) [#3]
Yes
It's very strange, the left/top side of the region is correct, but the right/down no.