Skip to content

Instantly share code, notes, and snippets.

@RafaelOliveira
Created July 13, 2015 21:00
Show Gist options
  • Save RafaelOliveira/e12cd0305f9384fcc9a9 to your computer and use it in GitHub Desktop.
Save RafaelOliveira/e12cd0305f9384fcc9a9 to your computer and use it in GitHub Desktop.
JsTouch
package;
import js.Browser;
import js.html.TouchEvent;
class JsTouch
{
public static var down:Bool = false;
public static var move:Bool = false;
public static var x:Float;
public static var y:Float;
public static function init()
{
var canvas = Browser.document.getElementsByTagName("canvas")[0];
canvas.addEventListener("touchstart", touchDown, false);
canvas.addEventListener("touchend", touchUp, false);
canvas.addEventListener("touchend", touchUp, false);
canvas.addEventListener("touchmove", touchMove, false);
}
public static function touchDown(event:TouchEvent):Void
{
down = true;
x = event.touches[0].clientX;
y = event.touches[0].clientY;
}
public static function touchUp(event:TouchEvent):Void
{
down = false;
move = false;
}
public static function touchMove(event:TouchEvent):Void
{
move = true;
x = event.touches[0].clientX;
y = event.touches[0].clientY;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment