Created
July 13, 2015 21:00
-
-
Save RafaelOliveira/e12cd0305f9384fcc9a9 to your computer and use it in GitHub Desktop.
JsTouch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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