Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement