Page 1 of 1

Key Down event in Actors Draw

PostPosted: Fri Jun 17, 2011 10:19 am
by foleyjo
Is there a way to script the keydown events. I've searched the forums but can find anything that I understand does this.

What I want to say is

If (keydown = leftarrow ) then xpeed = -2;
if (keydown == rightarrow) then xpeed = +2;

I also want to say if these 2 keys are not pressed xspeed = 0;

but..... only if the player is not jumping.

I think I know how to code all this other than the capturing of the key presses

Re: Key Down event in Actors Draw

PostPosted: Fri Jun 17, 2011 11:31 am
by savvy
this is a very interesting and usefull bit of code actually...

at the start of your draw script you need to write..
Code: Select all
char* key = GetKeyState();


then in order to see if a key is pressed use...
Code: Select all
if(key[KEY_LEFT]==1)
{
xpeed-=2;
}
if(key[KEY_RIGHT]==1)
{
xpeed+=2;
}

then to set the speed back to 0 use...
Code: Select all
if(key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
{
xpeed=0;
}


this is how its done :D

if you want to get a keyboard key, you need to use [KEY_w] lower case keys instead of capitals, you can find all of them in the game-editor documentation.
(go to help then documentation)

to restrict these to if its NOT jumping you need to use a jumping variable.. or if jump is 0 for example. (if jump is 0 the player cant jump so is probably jumping)
so..
Code: Select all
if(jump!=0)
{
//codes here
}

the use of != makes it say.. if jump is not equal to 0.

savvy
(+1 if this helps)

Re: Key Down event in Actors Draw

PostPosted: Fri Jun 17, 2011 11:50 am
by foleyjo
Thanks Savvy

I think this might give me that little bit of extra control of the player that I'm looking for.

:D

(+1'd as it does help)