Mike Halliday
09-03-2009, 05:16 PM
How do I detect multiple key presses?
An example:
I Press UP, then I press LEFT - Sprite moves diagonally. Unfortunately when I do this using the standard keypress detection my sprite starts moving up when I press the UP key, then moves left when I press the LEFT key.
It appears that only single key presses are registered.
Am I missing something? - Is there a simple way to do this?
Leginus
09-03-2009, 06:53 PM
As i understand it mike this is a shortcoming of windows mobile and not ppl. The only other way that I have seen it done in games is to have an onscreen joystick with 8 positions, as you couldnt use a 4 position one because you can only register 1 screen press at the same time as well. Lol gr8 planning from microsoft :0
Nicknack
09-03-2009, 09:39 PM
do you have this on mind?
#include "GameAPI.ppl"
func mainproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;
case (Msg$)
WM_CLOSE:
ShutGameAPI(hWnd$);
WM_KEYDOWN:
g_KeyEvent(wParam$, True);
WM_KEYUP:
g_KeyEvent(wParam$, False);
end;
return (ok$);
end;
func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:t
g_clear(0);
RenderSprites;
WM_TIMER:
if (g_key.vkDown$ and g_key.vkRight$)
OffsetSprite(sp$,1,1);
end;
if (g_key.vkA$)
PostMessage(hWnd$, WM_CLOSE, 0, 0);
end;
end;
return (true);
end;
func WinMain
h$ = newform({GAPI}, {GAPIClass}, &mainproc);
ShowWindow(h$, SW_SHOW);
ShowFPS(true, G_RGB(255, 255, 255));
InitGameAPIEx(h$, &GameProc, 240, 320, false, 5, 60);
global(sp$);
sp$=newsprite(null);
sEtspritewidth(sp$,10);
sEtspriteheight(sp$,10);
return (true);
end;
surely it doesn't work the same way directly in WM_KEYDOWN, but with the help of an extra variable for each keystate it should keep your fingers gliding, too ;)
mmtbb
09-18-2009, 11:49 PM
Mike,
You have to manually do this. You have to use an if() statement to chack if both buttons are down, then issue the command to move the sprite diagonal.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.