-
[RESOLVED] key presses not affecting right variables
Actionscript Code:
// button presses upKey = 38; downKey = 40; leftKey = 37; rightKey = 39; focusKey = 65; attack1Key = 83; attack2Key = 68; bombKey = 81; autoAttack1Key = 87; autoAttack2Key = 69; trace("durr"); var listener = new Object(); listener.onKeyDown = function() { var key = Key.getCode(); trace(key); switch (key) { case upKey : upDown = true; downDown = false; trace("banana"); case downKey : downDown = true; upDown = false; case leftKey : leftDown = true; rightDown = false; case rightKey : rightDown = true; leftDown = false; case focusKey : focus = true; case attack1Key : attack1 = true; case attack2Key : attack2 = true; case bombKey : bomb = true; case autoAttack1Key : if (autoAttack1 == true) { autoAttack1 = false; } if (autoAttack1 == false) { autoAttack1 = true; } case autoAttack2Key : if (autoAttack2 == true) { autoAttack2 = false; } if (autoAttack2 == false) { autoAttack2 = true; } } }; listener.onKeyUp = function() { var key2 = Key.getCode(); switch (key2) { case upKey : upDown = false; case downKey : downDown = false; case leftKey : leftDown = false; case rightKey : rightDown = false; case focusKey : focus = false; case attack1Key : attack1 = false; case attack2Key : attack2 = false; case bombKey : bomb = false; } }; Key.addListener(listener); onEnterFrame = function () { if (upDown == true) { player._y -= 10; } if (downDown == true) { player._y += 10; } if (leftDown == true) { player._x -= 10; } if (rightDown == true) { player._x += 10; } };
Rather than affecting one variable, one key press makes all the others true as well
-
Developing For Dunkets
Well, a couple things. First, the variables upDown, downDown, leftDown, and rightDown are never properly defined and should be local to the events. So assuming they're declared elsewhere you never put a break in the switch
PHP Code:
switch(key){ case upKey: upDown = true; downDown = false; break; case downKey : downDown = true; upDown = false; break; }
You need to break out of the switch once one is true.
-
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
|