KeyboardEvent "sticking"

56 views
Skip to first unread message

Gcs_dev

unread,
Sep 23, 2012, 1:27:44 PM9/23/12
to haxe...@googlegroups.com
Hello.
I'm using KeyboardEvents (KEY_DOWN and KEY_UP) on Lib.current.stage to change Bool vars which control player movement in an ENTER_FRAME, (if (kUp == true) player.vy -= speed).
The problem is that, when testing the game in Firefox (various player versions), the booleans seem to "stick" occasionally (more so in very big levels which take up a lot of memory) and the player will continue to move after releasing the key only to stop an indefinite amount of time later (usually a second or two) or conversely will not move for a second or two after key down. Mouse interaction seems to prompt the unsticking.

This doesn't seem to happen in the standalone player or the debug test player, only in the Firefox browser.
Has anyone come across this problem and how can I fix it?

Thanks for your time.

Rob Fell

unread,
Sep 24, 2012, 12:42:55 AM9/24/12
to haxe...@googlegroups.com
Yes, key events fire in the time between frames.  Therefore it is possible to set and unset such a stateful bool within an enter frame for a number of reasons, not all of them predictable or desirable to a state based input model.
 
One solution is to buffer the effects of the events.  E.g. an array of ups, and downs per keycode.  This array accumulates between frames but is only processed on the enter frame (with the corresponding state toggled accordingly).  Your code controls the buffer so it can even be processed one entry per frame, to ensure no key events are missed (albeit lagged) or to allow user input recordings.
 
I implemented a similar approach in the awe6 IInputKeyboard implementation, which may be helpful:
 
Flash driver:
which extends the abstract:

cittadino....@gmail.com

unread,
Sep 24, 2012, 3:19:12 PM9/24/12
to haxe...@googlegroups.com
Hi Rob and thanks for your very helpful reply.
Your Awe6 framework is seriously impressive work, congratulations. I'll be spending some time now reading through the classes to try to extract the bits and pieces of info I need for keyboard input. I'd never have guessed it would be such an arduous task.

Thanks again.
> --
>
> To post to this group haxe...@googlegroups.com
>
> http://groups.google.com/group/haxelang?hl=en
>
>  
>
>  
>
>  
>
>

Rob Fell

unread,
Sep 24, 2012, 3:51:28 PM9/24/12
to haxe...@googlegroups.com
You're welcome.  Yes this issue is not immediately apparent, especially in high frame rate swfs.
I wouldn't know for sure whether it's the only reason causing the problems you described, but it is one I've encountered before that presented similar symptoms.

Ashiq A.

unread,
Sep 29, 2012, 5:53:33 AM9/29/12
to haxe...@googlegroups.com
I'm using the KeyBinding library that Joshua suggested, and I'm not seeing any issues in my application yet. Can you try that and let us know if it fixes the problem?


--Ashiq

cittadino....@gmail.com

unread,
Sep 29, 2012, 8:20:36 PM9/29/12
to haxe...@googlegroups.com
Hello Ashiq and thank you for the reference to the KeyBinding class.
Unfortunately the problem occurs exactly as with simply adding KeyboardEvents to the stage i.e. sticking happens in Firefox but not in the standalone or in debug players.

Ashiq A.

unread,
Sep 29, 2012, 8:36:22 PM9/29/12
to haxe...@googlegroups.com
Okay, thanks for letting me know.

@Rob I will try awe6 next game spike -- already started one now so it's too late to bail out.

Thanks guys for the info.

--Ashiq
Reply all
Reply to author
Forward
0 new messages