Skip to content

Instantly share code, notes, and snippets.

@smks
Created August 26, 2015 19:14
Show Gist options
  • Save smks/8806238e42e039bd5a09 to your computer and use it in GitHub Desktop.
Save smks/8806238e42e039bd5a09 to your computer and use it in GitHub Desktop.
JoystickControls.hx
package smks.controls;
import flixel.ui.FlxAnalog;
import smks.player.Player;
/**
* @author Shaun Stone (SMKS) <shaunmstone@gmail.com>
* @shaunmstone
*/
class JoystickControls
{
var joystick:FlxAnalog;
var player:Player;
public function new(joystick:FlxAnalog, player:Player)
{
this.joystick = joystick;
this.player = player;
this.player.drag.x = 100;
this.player.drag.y = 100;
this.joystick.onPressed = movePlayer;
this.joystick.onUp = stopPlayer;
}
function stopPlayer():Void
{
this.player.acceleration.x = 0;
this.player.acceleration.y = 0;
}
function movePlayer():Void
{
var angle:Float = joystick.getAngle();
this.player.velocity.x = 10 * joystick.acceleration.x;
this.player.velocity.y = 10 * joystick.acceleration.y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment