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..
2 buttons at once
-
- Posts: 82
- Joined: Mon Jun 20, 2005 3:32 am
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
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
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
}
-
- Posts: 82
- Joined: Mon Jun 20, 2005 3:32 am
-
- Posts: 82
- Joined: Mon Jun 20, 2005 3:32 am