Keyboard event handling is what i'm after, primarily for controlling sprites in gamming. I'm not talking about incrementing a variable by 1 with a repeated keystroke. I'm looking to trap the key when pressed, so that when the trap is made for a particular event, the trap automatically causes a stop on that event, so recursive traps can never take place. The return from the trap routine automatically does an ON unless an explicit OFF has been performed inside the trap routine.
Say instead of having to continously tap on the 'Right Arrow Key' to have an object move to the Right, why not hold down on the 'Key' and have the object gradually slide to the right while having the key held down and have the object stop its movement upon the 'Key' being depressed. I have not yet to see this in any Flash Game . . .
Kind of a critical fundamental to have in a game
Life is a waste of Time, Time is a waste of Life, So why not get wasted all of the Time and enjoy the Time of your Life!
i started a reply to this, but i realized it would be better in a tutorial, so i wrote a quick tutorial and sent it over to flashkit. basically there's a way to detect on keyrelease, but it's not completely accurate, there's a slight delay. i'll post again if the tutorial goes up, keep your eye out for it.
I believe you are talking about capturing both Key-Down and Key-Up events? Alas, Flash simply cannot do that . Flash fires the Key-Press event as soon as the key is depressed. Holding a key down will result in repeated Key-Press events (at the repeat-rate of your keyboard, as defined by your OS).
Hardly ideal for gaming, I agree. Perhaps in Flash 5.
Works well for me and as far as I'm aware my settings are standard for a Windows 98 PC. In control panel my "repeat delay" is set to short and "repeat rate" is set in the middle (neither fast nor slow).
I'd be interested if it works well for other people....maybe Trigg can comment?
true, it will cause the action to be repeated on key press, but it's not smooth, try it. the key repeat process works so that when you press a key, it performs the action, then there is a slight delay until it loops repeatedly.
also with this you can't perform an action on key release, because it would be looping that action constantly
sorry if i was being unclear, your way works perfectly for the acceleration example, in fact i think people should use this in the asteroids games that are out there.
what i was referring to is the slight delay when you press the key, which you can't see in your example because the object doesn't have any inertia yet. this delay can cause an annoyance that is cropping up in alot of games now, the jump before you start moving. you can see it in the example below. http://www.goodnet.com/~kaustin/key_release.html
if you press 2 you can see your example, which for me jumps back and forth once before staying, and if you press 1 it just goes, but there's a delay when you release.
this is all kind of nit picking, but eliminating annoyances like these can make or break some games, you know?
You mean the sudden "teleportation"after you pressed the key to move the guy in the mc?
Well, easy: make an extra frame before the game really starts with only yhe character in it. Put a code in it where you say the X_position of the guy must be 200 (or any other) and also for the Y_position, so the character moves to that place... make sure these X and Y positions are... sorry, kinda vague... but try it out or mail me, I'll send ya a fla-example if I still find it on my pc.