Pages

Monday, November 8, 2010

using keys in your games

images

when you want use keys  you should noticed that have many function

like keyPressed(int keyCode),keyReleased(int keyCode) ,keyRepeated(int keyCode) if you want use all of them should have something for control number of key pressing and releasing and repeating. with this code detect which key is pressed

int gameAction = getGameAction(keyCode);
switch(gameAction){
case UP:
key= "[UP]";
break;
case DOWN:
key= "[DOWN]";
break;
case LEFT:
key= "[LEFT]";
break;
case RIGHT:
key= "[RIGHT]";
break;
case FIRE:
key= "[FIRE]";
break;
case GAME_A:
message = "[LEFT_UP]";
break;
case GAME_B:
message = "[RIGHT_UP]";
break;
case GAME_C:
key= "[LEFT_DOWN]";
break;
case GAME_D:
key= "[RIGHT_DOWN]";
break;
default:
key= "";
break;

you can add all of code in same function.then define value like speed; we assume that in our game when you continue on  key press you have more speed so add this code after detect key “speed++”;But after checking speed in real device you see that you object move slower than emulator.it  because that device can’t process graphic like computer and emulator.You have to use timer functions and class in your games or using smaller graphic file in next post you see how do that


No comments:

Post a Comment

linkwithin

Related Posts Plugin for WordPress, Blogger...