|
-
More problems with sprite movement
I fixed my first problem, and my practise project is starting to actually be able to do something. I can move my man with aswd and shoot moving balls with space, but there is an issue with it. When I'm moving my man by holding down a key, and then press space to shoot off a ball, then movement halts and you have to up and down the key again, to make the man continue to move.
Here is the code:
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveMan);
function moveMan(e:KeyboardEvent):void
{
var character:String = String.fromCharCode(e.charCode);
var oldKeyCode:int;
//Sets "awsd" as controls to move sprite
if (e.keyCode == 87)
{
man_mc.y -= 5;
oldKeyCode = e.keyCode;
}
if (e.keyCode == 83)
{
man_mc.y += 5;
oldKeyCode = e.keyCode;
}
if (e.keyCode == 65)
{
man_mc.x -= 5;
oldKeyCode = e.keyCode;
}
if (e.keyCode == 68)
{
man_mc.x += 5;
oldKeyCode = e.keyCode;
}
if (e.keyCode == 32)
{
//Put a ball on the stage
var newBall:ball = new ball();
this.addChild(newBall);
newBall.x = man_mc.x;
newBall.y = man_mc.y + (man_mc.height / 2);
e.keyCode = oldKeyCode;
}
}
(There is also some code in the ball mc, that makes the ball fly sideways out of the screen when "fired")
As you might be able to see, I tried using another variable to store the old key code in, and switch it after the actions of a space press has occured.
So, can anyone tell me how to make the sprite move after another key has been pressed, without having to up and down the key again?
As always, all help is much appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|