You Are Here:

Community: Developer Discussion Boards

#1 Old Unhappy How to make Keypress() slow down? - 2005-06-09, 02:03

Join Date: Feb 2005
Posts: 7
xqwww
Offline
Registered User
I am writing a j2me RPG game, in the main loop, I wrote a Keypress() function.

private void keyPressed() {
int keyStates = getKeyStates();

// Left
if ((keyStates & LEFT_PRESSED) != 0) {
pointer move once.
..........
}

} \\ something like this.

when I press left (4) key. the pointer in game always move twice. It seems main thread accept key event too sensitive, even I press and release very quickly. we definetly do not want to these key make us crazy. Does anyone can help me out ?

Thanks
Reply With Quote

#2 Old Re: How to make Keypress() slow down? - 2005-09-16, 14:49

Join Date: Jul 2005
Posts: 2
surinderpalkundal
Offline
Registered User
Well for the keypressed being called twice it might be due to the keyReleased() try removing it.

As for slowing the reponse of keypressed you can do something like this

long current =System.currentTimeMillis();

long gap ;//set this as per your choice

private void keyPressed() {

if(System.currentTimeMillis()-current<gap)
{
return;
}

current =System.currentTimeMillis();


int keyStates = getKeyStates();

// Left
if ((keyStates & LEFT_PRESSED) != 0) {
pointer move once.
..........
}

} \\ something like this.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia