-
This is my first time using Haxe, so I'm doing their little tutorial. I'm a bit stumped on this and don't know how to fix it. package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
import flixel.util.FlxColor;
class Player extends FlxSprite
{
static inline var SPEED:Float = 200;
var newAngle(default, null):Float;
public function new(x:Float = 0, y:Float = 0)
{
super(x, y);
makeGraphic(16, 16, FlxColor.BLUE);
drag.x = drag.y = 1600;
}
// WASD handler
function updateMovement()
{
var up:Bool = false;
var down:Bool = false;
var left:Bool = false;
var right:Bool = false;
up = FlxG.keys.anyPressed([UP, W]);
down = FlxG.keys.anyPressed([DOWN, S]);
left = FlxG.keys.anyPressed([LEFT, A]);
right = FlxG.keys.anyPressed([RIGHT, D]);
// cancel opposite keys
if (up && down)
up = down = false;
if (left && right)
left = right = false;
// move when key pressed
if (up || down || left || right)
{
var newAngle:Float = 0;
if (up)
{
newAngle = -90;
if (left)
newAngle -= 45;
else if (right)
newAngle += 45;
}
else if (down)
{
newAngle = 90;
if (left)
newAngle += 45;
else if (right)
newAngle -= 45;
}
else if (left)
newAngle = 180;
else if (right)
newAngle = 0;
}
velocity.set(SPEED, 0);
velocity.rotate(FlxPoint.weak(0, 0), newAngle);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
when asking for help, be sure to say what actual problems you're running into. are there compile errors, or runtime errors? If so, list them. is something behaving different than how you expected? if so what behavior did you expect and what are you observing? Don't just post an entire class and say that some unspecified problem exists, somewhere |
Beta Was this translation helpful? Give feedback.
when asking for help, be sure to say what actual problems you're running into. are there compile errors, or runtime errors? If so, list them. is something behaving different than how you expected? if so what behavior did you expect and what are you observing?
Don't just post an entire class and say that some unspecified problem exists, somewhere