Sticky Movement Issue

14 posts

Flag Post

I’m working on a game in a small team and everyone who tests the game sometimes has their keys sticking and they have to fiddle around to fix it again. This isn’t occurring for me though, so it’s really difficult to debug since I can’t even recreate it. Is this kind of issue common within flash? I think I’ve heard about it, but I’m not exactly sure.
Thanks.

 
Flag Post

Are they using IE?

 
Flag Post
Originally posted by Feffers:

I’m working on a game in a small team and everyone who tests the game sometimes has their keys sticking and they have to fiddle around to fix it again. This isn’t occurring for me though, so it’s really difficult to debug since I can’t even recreate it. Is this kind of issue common within flash? I think I’ve heard about it, but I’m not exactly sure.
Thanks.

Show us your keypress code- it’s likely one of the if statements is butchered.

 
Flag Post
Originally posted by saybox:

Are they using IE?

Tried both firefox and the standalone – same result.

Originally posted by RTL_Shadow:

Show us your keypress code- it’s likely one of the if statements is butchered.

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);

private function keyDown(ev:KeyboardEvent):void {
     if (ev.keyCode == asciinum) {
            //move
     }
}

Simple booleans when key down and key up to put on enterframe and move the character.
Not exactly sure what you mean by butchered.

 
Flag Post

That code doesn’t work smoothly for key presses. You should use a system of booleans and check what keys are down on EVENT.ENTER_FRAME if you plan on having a non-stuttering movement.

 
Flag Post

I agree with UG on this one… When I first started out, I did it the same way as you are doing it here… It caused problems when pressing more than one key at a time.

I usually make some event listeners for key up and key down, and then have a boolean for each relevant key that I set to true if down, false if up – then just check for those in the enter_frame.

 
Flag Post

I think you guys misunderstood, that’s what I am doing.

 
Flag Post

Based on the code you posted, it is not what you are doing.

 
Flag Post

The code I posted was displaying how I captured the key inputs. Below it I said I was setting booleans to true/false depending on keyDown or keyUp as well as putting it on an enterFrame event to move the character.

 
Flag Post

Given the comment “// move” the more probable code there might be was exactly “move by function” and not “set a boolean”. You have not provided enough code for a qualified decision.

 
Flag Post

Alright, I’ll admit I made a typo. Pseudo on what I’m doing:

var rightKeyDown:Boolean <- false;

//keydown event listener
if ev.keyCode == right {
      rightKeyDown <- true
}

//keyup event listener
if ev.keyCode == right {
      rightKeyDown <- false
}

//enterframe event in character class
if rightKeyDown {
       x += speed
}

That’s how it should be done, right? To elaborate with the actual problem, I myself am not getting any sticky keys, it runs smooth and nicely. However, 2 other people who have tested it can recreate the issue where if they hold, for example, the right key down, then hold the up key down, quickly switching to go left will result in them going up/right only stopping when they have put the right and up key up again. It doesn’t happen all the time, but they are able to recreate it.

 
Flag Post

What kind of keyboard do they have? It could be a problem with the mechanics of their keyboard. Some (cheap) keyboards apparently are built so that they can’t respond properly to multiple keypresses/keyreleases (I forget the anachronym for the number of simultaneous keypresses a keyboard can handle).

If it is not that, there are two other possibilities (from what I’ve read): security settings (most notoriously IE’s protected mode) and key repeat settings. I hypothesize that they are both symptoms of the same cause, however (being the way Flash handles key input processing — see the post by chriskallen1 in this thread. Unless you have a lot of listeners or something, I would’ve thought how you’re doing it would be fine — though I would put ev.keyCode into a dedicated var rather than access ev’s keyCode for each test. Also, I thought I read somewhere that assigning priorities to your listeners can be of some help (rather than using the default, give a higher priority to the keyup listener and the keydown listener)).

 
Flag Post

@Feffers: Here.

You’re already on the right track, so unless you want to make your own key listening class for practice, you might want to just use skyboy’s version instead.

 
Flag Post

Thanks a lot for the responses, I’ll look into it.