How do I get the AWSD keys to work as smoothly as the arrow keys. I can put the arrow keys inside an enterFrame
[AS]onClipEvent (enterFrame) {
//move the tank
if (Key.isDown(Key.RIGHT)) {
this._rotation += 10;
} else if (Key.isDown(Key.LEFT)) {
this._rotation -= 10;
[/AS]
But the AWD keys I can only get to work if I put them inside a keyDown
[AS]
onClipEvent (keyDown) {
//move the tank
if (Key.getCode() == 68) {
this._rotation += 10;
} else if (Key.getCode() == 65) {
this._rotation -= 10;
} else if (Key.getCode() == 87) {
[/AS]
If I put the AWD keys inside an enterFrame they run until I push another button
Thanks in advance!
-Tobias
http://www.gelstoncafe.com
Check the differences in your if statements;)
For the enterFrame you use Key.isDown(), but for the keyDown you use Key.getCode()
LostinBeta,
I have never been successful using
[AS]if (Key.isDown() == 68) {[/AS]
inside an enterFrame - am I doing something wrong?
Thanks,
Tobias
Yeah it is [AS]if (Key.isDown(68))[/AS] not [AS]if (Key.isDown() == 68)[/AS]
Also what are you using this for? There may be a way to optimize it using Key Listeners or through keyDown so that its not running in an onEnterFrame and using up cpu resources.
Thanks! That works much much better
I am using this to move a tank around the screen - kind of like the original combat for atari
Here is all my keycode - if there is a more efficient way I would love to see it! Thanks for you time.
[AS]
onClipEvent (enterFrame) {
//move the tank
if (Key.isDown(68)){
this._rotation += 10;
} else if (Key.isDown(65)) {
this._rotation -= 10;
} else if (Key.isDown(87)) {
this._x += (Math.cos(Math.PI/180this._rotation)_root.speed);
this._y += (Math.sin(Math.PI/180this._rotation)_root.speed);
} else if ((Key.isDown(Key.SHIFT)) and (_root.timer2 == 0)) {
depth++;
name = “projectile”+depth;
_root.shot2.duplicateMovieClip(name, depth);
_root.timer2 = 1;
_root[name]._x = this._x;
//*Math.cos(angle);
_root[name]._y = this._y;
//*Math.sin(angle);
}
}
[/AS]
THANKS
Considering what you are using it for I think you are fine.
Just a tip though, when using if/else statements you must remember that the else only gets activated if the previous statement is false. I noticed you contained everything as if/else if statements. Well this may cause some complications in movement, so you may want to put some things as seperate if statments if it causes any problems.
Thanks! I appreciate your help!