Fix for touch event coordinates.

This commit is contained in:
MrCdK
2014-11-21 00:07:43 +01:00
parent 0693fc9fc5
commit f2d8b91306

View File

@@ -63,14 +63,34 @@ import flash.Lib;
if (window != null && window.element != null) { if (window != null && window.element != null) {
var rect = window.element.getBoundingClientRect (); if (window.canvas != null) {
eventInfo.x = (touch.pageX - rect.left) * (window.width / rect.width);
eventInfo.y = (touch.pageY - rect.top) * (window.height / rect.height); var rect = window.canvas.getBoundingClientRect ();
eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width);
eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height);
} else if (window.div != null) {
var rect = window.div.getBoundingClientRect ();
//eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width);
eventInfo.x = (touch.clientX - rect.left);
//eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height);
eventInfo.y = (touch.clientY - rect.top);
} else {
var rect = window.element.getBoundingClientRect ();
eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width);
eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height);
}
} else { } else {
eventInfo.x = touch.pageX; eventInfo.x = touch.clientX;
eventInfo.y = touch.pageY; eventInfo.y = touch.clientY;
} }