forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

2 buttons at once

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
JJPeerless



Joined: 20 Jun 2005
Posts: 82

PostPosted: Sun Jul 03, 2005 5:55 am    Post subject: 2 buttons at once Reply with quote

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
View user's profile Send private message
Hippo



Joined: 25 Jun 2005
Posts: 19

PostPosted: Sun Jul 03, 2005 6:36 am    Post subject: Reply with quote

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
View user's profile Send private message
subbie



Joined: 05 May 2005
Posts: 122

PostPosted: Sun Jul 03, 2005 6:39 am    Post subject: Reply with quote

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
View user's profile Send private message
JJPeerless



Joined: 20 Jun 2005
Posts: 82

PostPosted: Mon Jul 04, 2005 5:11 am    Post subject: Reply with quote

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
View user's profile Send private message
Hippo



Joined: 25 Jun 2005
Posts: 19

PostPosted: Mon Jul 04, 2005 6:01 am    Post subject: Reply with quote

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
View user's profile Send private message
JJPeerless



Joined: 20 Jun 2005
Posts: 82

PostPosted: Mon Jul 04, 2005 6:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Hippo



Joined: 25 Jun 2005
Posts: 19

PostPosted: Mon Jul 04, 2005 6:43 am    Post subject: Reply with quote

You might try changing REPEAT_TIME to something lower... *shrug*
Back to top
View user's profile Send private message
JJPeerless



Joined: 20 Jun 2005
Posts: 82

PostPosted: Mon Jul 04, 2005 8:02 am    Post subject: Reply with quote

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

amazing. =)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group