if(keyUp[KEY_3] == 1) ??

Talk about making games.

if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sun May 13, 2012 5:46 pm

We know for:
char *key = GetKeyState();
if(key[KEY_3] == 1)
{
}

But how to do that like:
char *key = GetKeyState();
if(keyUP[KEY_3] == 1)
{
}
help.png
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby skydereign » Sun May 13, 2012 6:11 pm

There isn't a function for that. You can do this though (have two keys type variables, last_key needs to be declared globally).
Code: Select all
char*key = GetKeyState();

if(key[KEY_3]==0 && last_key[KEY_3]==1)
{
    // keyup
}
last_key = GetKeyState(); // this way it next event it knows what the previous frame had
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sun May 13, 2012 6:17 pm

Mhm i know supported function..but what to use..
After that:
Code: Select all
char*key = GetKeyState();

if(key[KEY_3]==0 && last_key[KEY_3]==1)
{
    ExitGame();

?
-Need a pointer
And is that can make the same effect as keyup?
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby skydereign » Sun May 13, 2012 6:29 pm

First of all, that isn't the code I gave you, and I did mention you need to declare the last_key pointer globally. But it actually doesn't work quite that nicely, since the GetKeyState function just points it to where the key variables are. You can however save individual states, to check for keyups.
Global Code
Code: Select all
int key3 = 0;

Draw Event
Code: Select all
char* key = GetKeyState();

if(key[KEY_3]==0 && key3==1)
{
    ExitGame();
}

key3 = key[KEY_3];
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sun May 13, 2012 6:41 pm

Actually it works 100% ;p
Ok

So ..can you tell me something more :oops:
Well..how 1 actor can be earsed pixel by pixel (gradually)
Im not so good in drawing ;dd
(+1)
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby savvy » Sun May 13, 2012 6:52 pm

You cant do that unless you add it as an animation, or have the actor a canvas actor (drawn in).

savvy
--> 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: if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sun May 13, 2012 6:58 pm

with animation is hard..with cave i know i can..but how canvas can delete that object:
actor.png
actor.png (1.19 KiB) Viewed 4822 times

(yvelocity+)
?
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby AliceXIII » Fri May 18, 2012 3:04 pm

hahaha i do exactly what you want in ever program i make :P

it's simple just make a key up event set it to any key then in the script use this instead:
Code: Select all
int key=getLastKey();

switch(key)
{
    case KEY_3:
    //do what you want here;
    break;
}


can be used the same way with key down event if you like to use switches instead of if's like me :P
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby skydereign » Fri May 18, 2012 8:35 pm

Well, that actually won't work properly. For that method of keyup, you have to assume that only one key is pressed at a time. The getLastKey is not a getLastKeyChange function, but rather a getLastKeyPressed function. That means if you hold down space, and then press left, when you let go of space your code will trigger a keyup left. However using it for keydown events is rather handy, and it guarantees the correct key press.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby savvy » Sat May 19, 2012 9:51 am

Code: Select all
char* key = GetKeyState();
if(key[KEY_3]==1&&pressed==0)
{
pressed=1;
ExitGame();
}
if(key[KEY_3]==0)
{
pressed=0;
}

this is how iv'e always done it... The pressed variable is an actor variable.
But then I only ever need this for use with 1 button, when making a jump effect using this.

savvy
--> 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: if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sat May 19, 2012 11:42 am

I make it correctly with the first method and now i use main edited:
Global code:
Code: Select all
#define key3 = 0;//or key3 = 0 (key3 = variable)


Char:
Code: Select all
char* key = GetKeyState();
if(key[KEY_3]==0 && key3==1)
{
    ExitGame();
}

key3 = key[KEY_3];


and i am not sure for that:

Code: Select all
//key down event
#define key3
"actor" = GetKeyState();
if(key[KEY_3]==1) {
key3=0;
}

if(key[KEY_3]==0) {
key3=1;
}

if(key3==1) {
ExitGame()
}
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby skydereign » Sat May 19, 2012 4:20 pm

That isn't how #define works (and in this case you don't need a #define). All you need to do is actually declare an int called key3.
Global Code
Code: Select all
int key3;


Next thing is, setting a literal string equal to GetKeyState doesn't make sense either.
Code: Select all
// "actor" = GetKeyState();
// that doesn't make sense

char* key = GetKeyState(); // this does make sense
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby bat78 » Sat May 19, 2012 7:06 pm

mhm
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby AliceXIII » Fri May 25, 2012 3:13 pm

skydereign wrote:Well, that actually won't work properly. For that method of keyup, you have to assume that only one key is pressed at a time. The getLastKey is not a getLastKeyChange function, but rather a getLastKeyPressed function. That means if you hold down space, and then press left, when you let go of space your code will trigger a keyup left. However using it for keydown events is rather handy, and it guarantees the correct key press.



yeah thats why i only use that method with key up if i want to get the right animation when the player stops :P
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: if(keyUp[KEY_3] == 1) ??

Postby Game A Gogo » Thu May 31, 2012 4:35 pm

I think I'll make a simple function for keyup and keydown later when I get home, given I can make it work :P
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron