Hey guys! I started a little fun Halloween themed game last night and it is a nice change of pace from my current game project. I have a character who walks around a world, this is my control code, don’t make fun of me:
//player controls
if (Input.check(Key.LEFT) && !Input.check(Key.RIGHT) && !Input.check(Key.DOWN) && !Input.check(Key.UP))
{
xSpeed -= power;
pressed = true;
playerSprite.play("left");
direction = 1;
}
if (Input.check(Key.RIGHT) && !Input.check(Key.LEFT) && !Input.check(Key.DOWN) && !Input.check(Key.UP))
{
xSpeed += power;
pressed = true;
playerSprite.play("right");
direction = 2;
}
if (Input.check(Key.UP) && !Input.check(Key.DOWN) && !Input.check(Key.LEFT) && !Input.check(Key.RIGHT))
{
ySpeed -= power;
pressed = true;
playerSprite.play("up");
direction = 3;
}
if (Input.check(Key.DOWN) && !Input.check(Key.UP) && !Input.check(Key.LEFT) && !Input.check(Key.RIGHT))
{
ySpeed += power;
pressed = true;
playerSprite.play("down");
direction = 4;
}
//end of control code
This is how I play the footsteps sounds:
if (Input.pressed(Key.LEFT) || Input.pressed(Key.RIGHT) || Input.pressed(Key.UP) || Input.pressed(Key.DOWN))
{
playSound();
}
This is the playSound method:
private function playSound():void
{
sfxWalk.loop(.5);
}
It works without playing the sounds ten million times and being all glitchy. The issue I am having is if say I am walking to the left, the the left key is check and pressed, then I press another arrow key while holding the left key, then release the left key, the character will move in the new direction but there will be no sound. I know this is a fundamental issue, but I was hoping to get some solid guidance so my walking and sounds for games to come is not so finicky.
Thanks in advance all from Flashpunk!