Key.isDown / getAscii() problems
I'm having some trouble detecting keypresses.
Woking with the arrow keys works fine, but using getAscii() is having problems.
I tried using:
if (getAscii(100)) {//do stuff;};
but the issue is that once you press a key, getAscii() keeps returning the value of the last key pessed even after you stop pessing it.
I tied using a keyDown listener, instead of onEnteFame and couldn't get it to work at all.
I tried searching these foums, but some of the solutions had all the code deleted... odd.
How do I add the ability to add key detection for the other keyboard keys to this code?
xspeed = 0;
yspeed = 0;
this.onEnterFrame = function() {
if (Key.isDown(Key.LEFT)) {
xspeed += -3;
};
if (Key.isDown(Key.RIGHT)) {
xspeed += 3;
};
if (Key.isDown(Key.UP)) {
yspeed += -3;
};
if (Key.isDown(Key.DOWN)) {
yspeed += 3;
};
xspeed *= .8;
yspeed *= .8;
if (Math.abs(xspeed) < 1) {xspeed = 0;};
if (Math.abs(yspeed) < 1) {yspeed = 0;};
if (xspeed <> 0 or yspeed <> 0) {
_root.Map._x += xspeed;
_root.Map._y += yspeed;
};
}
(The code has a few exta lines to make the accelleration nice and smooth.)