2 buttons at once

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

2 buttons at once

Post by JJPeerless »

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..
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

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.
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

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.
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

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
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

Try this:

Code: Select all

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
}
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

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
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

You might try changing REPEAT_TIME to something lower... *shrug*
JJPeerless
Posts: 82
Joined: Mon Jun 20, 2005 3:32 am

Post by JJPeerless »

thanks, i lowered that alot..and it works really smooth..

amazing. =)
Post Reply