Hey all... The new game project is going pretty well, but here comes another question... Is there a way to get notification of repeat keyboard events? I.e., hold down the left arrow key in a desktop build and you will get one KeyDown message, but nothing else (or did I miss something?). If this is the case, how can I allow for continual movement when holding a button? Do I need to override WndProc? Thanks!
I don't know if this is something specific to GapiDraw (ie you are using its input handler) or not.
For regular win32 development you get two messages for every key press. One when it was pressed (WM_KEYDOWN) and one when it was released (WM_KEYUP). So if you want to do "repeats" then you just trigger an event ever so often as long as the key is pressed. Typically you would have an array representing all the key codes, and set them to 1 or 0 depending on whether or not that key is down. Make sure anything you do is time based and not frame based, or else your events will be bound to the speed the device is rendering (IE you would get to shoot faster on faster devices).
Dan East
Set a bool saying the key is currently depressed in the KeyDown method, then reset it in KeyUp when it is released. In ProcessNextFrame, act on that bool depending on its state. In otherwords, don't do any processing on the key state in the KeyUp/KeyDown methods. And as Dan says, be sure you handle your sprite movement using a time based method.
Yesm I thought of the rather obvious solution after posting, but I was hoping there was some mechanism in GD for it specifically (I thought I saw something about a repeat event in the docs). Ah well, this will work well too. Thanks for the replies!
Hi,
I know its slightly off topic but why is it always best to use time based animation instead of some form of frame counting?
TIA
I have to admit I don't even know what the term "time-based animation" really means.
I always limit my games to some specific frame rate and base everything off that. I mean, if it's limited to 30FPS for instance (usually my choice) and I can guarantee that the frame rate will always be constant (based on the fact that if it's steady on my E-125 then I assume any modern device will handle it without trouble), then I can make sure everything works properly at that speed and I'm good to go.
Is THAT time-based?
By limiting your fps your are basically limiting your program in a "time based" way. What they are talking about is letting the rendering engine display as many fps as it can handel on the current device while limiting the parts of the functions that update the gamestate(so you dont end up having to press the keys as fast as your framerate).
Time based animation infers that every specified 'tick' increments the animation frame. That 'tick' could be every 20ms, 50ms, 100ms... anything you define it to be. For instance, if you want 10fps animation for a walking animation, then your 'tick' would be 100ms. If you are on a faster processor, your animations will always produce the same motion at the same speed. If you weren't time based and moved to a faster processor, your animations would speed up accordingly. If you are on a slower processor - one that can't keep up with the defined 'tick' time, then you could conceivably skip missed frames to maintain the proper animation speed.
Anonymous: Let me clarify for you then, by time based I meant animation that relies on a timer event, exactly as PPC states later.
If I understand you correctly then you are saying that you set a limit in Gapidraw of say 30 fps and then count how many frames have elapsed before proceeding to display a new sprite frame or process some form of action?
This is what I have been doing, is it better though to use one or many timers to control your sprite animation, actions etc or make the assumption that a device will reach 30fps if it manages to do so on a low spec one?
The above post is me by the way
I've just found the earlier thread, ta very much.
Hi fzammetti,
If you're using GapiApplication, you can try commenting out line 443 of GapiApplication.cpp.
if (!(lParam & 0x40000000)){
Whenever a key is pressed, the code in your KeyDown event will be called while it remains pressed. It works for me.
sbl: Is this safe to use? I found this solution on another thread.
egarayblas: It's safe to use. Just remember that the delay between keyboard repeat events is a user-specified setting (can be set in the control panel). So on some devices events will happen really often, and on some devices events will happen very seldom. So IMHO using keyboard repeat events for other stuff than word processors is pretty useless...