Skip to content

Instantly share code, notes, and snippets.

@kdelwat
Created July 13, 2017 23:10
Show Gist options
  • Save kdelwat/4651f9af2e0f050cfd4edc601eea6334 to your computer and use it in GitHub Desktop.
Save kdelwat/4651f9af2e0f050cfd4edc601eea6334 to your computer and use it in GitHub Desktop.
Touch controls for Code Camp World
var mouseDeadZone = 50;
if (this.game.getMouseX() > this.getXPosition() + mouseDeadZone)
{
this.setXSpeed(100);
this.setYSpeed(0);
this.playAnimation('Right');
}
else if (this.game.getMouseX() < this.getXPosition() - mouseDeadZone)
{
this.setXSpeed(-100);
this.setYSpeed(0);
this.playAnimation('Left');
}
else if (this.game.getMouseY() < this.getYPosition() - mouseDeadZone)
{
this.setXSpeed(0);
this.setYSpeed(-100);
}
else if (this.game.getMouseY() > this.getYPosition() + mouseDeadZone)
{
this.setXSpeed(0);
this.setYSpeed(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment