| View previous topic :: View next topic |
| Author |
Message |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Sun Jul 03, 2005 5:55 am Post subject: 2 buttons at once |
|
|
hey..my game is coming along great, but im having a little problem now..
every frame i check for keypress, and it can only detect one key at a time..like say im holding the Right d-pad to scroll right..then i wanna press X to jump..when i press X it stops going right, then the next frame, only if i let go of X, will it continue to go right...how can i have it detect both Xand Right..and then call my functions for right and X independently..
im using the controller.c and controller.h files from someone elses project..
i already modified it by getting rid of the while(1) for checking for key presses so that it doesnt only act when a key is pressed..
thanks.. |
|
| Back to top |
|
 |
Hippo
Joined: 25 Jun 2005 Posts: 19
|
Posted: Sun Jul 03, 2005 6:36 am Post subject: |
|
|
| You'll have to modify the Control function (I think). Try having it return "key" and use the code at the end of Control (but put it wherever you need it) to test for which buttons are being pressed. |
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Sun Jul 03, 2005 6:39 am Post subject: |
|
|
Post some code.
Maybe your doing if( button == X_KEY ) insted of doing if( button & X_KEY ).
Input uses a bit field and multiple bits can be set so comparing an equal would not work. |
|
| Back to top |
|
 |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Mon Jul 04, 2005 5:11 am Post subject: |
|
|
int Control(void) {
unsigned long key;
int i;
key = Read_Key();
if (key & CTRL_SQUARE) {return 1;}
if (key & CTRL_TRIANGLE) {return 2;}
if (key & CTRL_CIRCLE) {return 3;}
if (key & CTRL_CROSS) {return 4;}
if (key & CTRL_UP) {return 5;}
if (key & CTRL_DOWN) {return 6;}
if (key & CTRL_LEFT) {return 7;}
if (key & CTRL_RIGHT) {return 8;}
if (key & CTRL_START) {return 9;}
if (key & CTRL_SELECT) {return 10;}
if (key & CTRL_LTRIGGER) {return 11;}
if (key & CTRL_RTRIGGER) {return 12;}
return 0;
}
thats in my controller.c
and in my main game i use
void checkPress(void)
{
switch(Control())
{
case 1:
//put code here for square button
break;
case 2:
//put code here for triangle button
break;
case 3:
//put code here for circle button
break;
case 4:
/put code here for X button
break;
case 5:
//code for up button
break;
case 6:
//code for down button
break;
case 7:
//put code here for dpad left
break;
case 8:
//put code here for dpad right
}
break;
case 9:
//put code here for start button
break;
case 10:
//put code here for select button
break;
case 11:
//put code here for left shoulder button
break;
case 12:
//put code here for right shoulder button
break;
}
}
and i call CheckPress() every frame |
|
| Back to top |
|
 |
Hippo
Joined: 25 Jun 2005 Posts: 19
|
Posted: Mon Jul 04, 2005 6:01 am Post subject: |
|
|
Try this:
| Code: | unsigned long Control(void)
{
return Read_Key();
}
void checkPress(void)
{
if (key & CTRL_SQUARE)
{
// square button is pressed
}
if (key & CTRL_TRIANGLE)
{
// triangle button is pressed
}
// and so on
} |
|
|
| Back to top |
|
 |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Mon Jul 04, 2005 6:13 am Post subject: |
|
|
| yeaup, thats exactly what i did right before i checked back here..works slightly better..still a little "laggy" or a slight pause..not sure why |
|
| Back to top |
|
 |
Hippo
Joined: 25 Jun 2005 Posts: 19
|
Posted: Mon Jul 04, 2005 6:43 am Post subject: |
|
|
| You might try changing REPEAT_TIME to something lower... *shrug* |
|
| Back to top |
|
 |
JJPeerless
Joined: 20 Jun 2005 Posts: 82
|
Posted: Mon Jul 04, 2005 8:02 am Post subject: |
|
|
thanks, i lowered that alot..and it works really smooth..
amazing. =) |
|
| Back to top |
|
 |
|