if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 5:46 pm
by bat78
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)
{
}
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:11 pm
by skydereign
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
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:17 pm
by bat78
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?
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:29 pm
by skydereign
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];
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:41 pm
by bat78
Actually it works 100% ;p
Ok
So ..can you tell me something more
Well..how 1 actor can be earsed pixel by pixel (gradually)
Im not so good in drawing ;dd
(+1)
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:52 pm
by savvy
You cant do that unless you add it as an animation, or have the actor a canvas actor (drawn in).
savvy
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sun May 13, 2012 6:58 pm
by bat78
with animation is hard..with cave i know i can..but how canvas can delete that object:
- actor.png (1.19 KiB) Viewed 4814 times
(yvelocity+)
?
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Fri May 18, 2012 3:04 pm
by AliceXIII
hahaha i do exactly what you want in ever program i make
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
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Fri May 18, 2012 8:35 pm
by skydereign
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.
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sat May 19, 2012 9:51 am
by savvy
- 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
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sat May 19, 2012 11:42 am
by bat78
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()
}
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Sat May 19, 2012 4:20 pm
by skydereign
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
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Fri May 25, 2012 3:13 pm
by AliceXIII
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
Re: if(keyUp[KEY_3] == 1) ??
Posted:
Thu May 31, 2012 4:35 pm
by Game A Gogo
I think I'll make a simple function for keyup and keydown later when I get home, given I can make it work