Key Down event in Actors Draw

Non-platform specific questions.

Key Down event in Actors Draw

Postby foleyjo » Fri Jun 17, 2011 10:19 am

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
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Key Down event in Actors Draw

Postby savvy » Fri Jun 17, 2011 11:31 am

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)
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Key Down event in Actors Draw

Postby foleyjo » Fri Jun 17, 2011 11:50 am

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)
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest