Created
August 26, 2015 19:14
-
-
Save smks/8806238e42e039bd5a09 to your computer and use it in GitHub Desktop.
JoystickControls.hx
This file contains 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 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