Skip to content

Instantly share code, notes, and snippets.

@cacheleocode
Last active December 20, 2015 02:39
Show Gist options
  • Select an option

  • Save cacheleocode/6058315 to your computer and use it in GitHub Desktop.

Select an option

Save cacheleocode/6058315 to your computer and use it in GitHub Desktop.
// for use in stage action creationComplete
this.swipeStartX;
this.swipeEndX;
this.swipeStartY;
this.swipeEndY;
this.swipePadding = 60; // prevent swipe when clicking
this.onSwipeLeft = function()
{
// execute
}
this.onSwipeRight = function()
{
// execute
}
this.onStop = function()
{
sym.stop();
}
this.onSwipe = function()
{
if(this.swipeEndY < this.swipeStartY - this.swipePadding) // swipe up
{
this.onSwipeUp();
}
else if(this.swipeStartY < this.swipeEndY - this.swipePadding) // swipe down
{
this.onSwipeDown();
}
else if(this.swipeStartX < this.swipeEndX - this.swipePadding) // swipe right (scrub to left)
{
this.onSwipeLeft();
}
else if( this.swipeEndX < this.swipeStartX - this.swipePadding ) // swipe left (scrub to right)
{
this.onSwipeRight();
}
}
// for use in stage action touchend
if (e.pageX == undefined)
{
var touch = e.originalEvent.touches [0] || e.originalEvent.changedTouches [0];
this.swipeEndX = touch.pageX;
this.onSwipe();
}
if (e.pageY == undefined)
{
var touch = e.originalEvent.touches [0] || e.originalEvent.changedTouches [0];
this.swipeEndY = touch.pageY;
this.onSwipe();
}
// for use in stage action touchstart
if (e.pageX == undefined)
{
var touch = e.originalEvent.touches [0] || e.originalEvent.changedTouches [0];
this.swipeStartX = touch.pageX;
}
if (e.pageY == undefined)
{
var touch = e.originalEvent.touches [0] || e.originalEvent.changedTouches [0];
this.swipeStartY = touch.pageY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment