Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (602)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  J2ME button control problems  (Read 2803 times)
0 Members and 1 Guest are viewing this topic.
Offline monopolyli

Senior Newbie




Java games rock!


« Posted 2005-02-01 13:01:31 »

Hello everybody,
I have a problem about the button (e.g KEY_NUM1, KEY_NUM2 .... etc), Why the buttons are disable (i.e. no action after pressing it) except KEY_STAR and KEY_POUND?
All are disable such as KEY_NUM1, KEY_NUM2 ..... KEY_NUM9.
My program like below:

switch(keycode){
case KEY_STAR:
System.out.println("CDE");
break;
}
switch(keycode)
{
case KEY_POUND:
System.out.println("ABC");
break;
}


Thank you very much~
Offline davidaprice

Junior Devvie





« Reply #1 - Posted 2005-02-02 09:39:42 »

If you're using a MIDP 2.0 GameCanvas and you've passed 'true' as the argument for the constructor parameter 'suppressKeyEvents', then you won't get keyPressed etc. callbacks for keys which correspond to game keys UP, DOWN, LEFT, RIGHT, FIRE, GAME_A..GAME_D. It might be that the phone you're using has a mapping like:
KEY_NUM1 -> GAME_A
KEY_NUM2 -> UP
KEY_NUM3 -> GAME_B
KEY_NUM4 -> LEFT
KEY_NUM5 -> FIRE
KEY_NUM6 -> RIGHT
KEY_NUM7 -> GAME_C
KEY_NUM8 -> DOWN
KEY_NUM9 -> GAME_D
So then you'd only get keyPressed callbacks for KEY_STAR, KEY_NUM0 & KEY_POUND.

If this isn't your answer, then please supply more information: what kind of Canvas / GameCanvas are you using, and what phone model?
Offline monopolyli

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-02-02 12:30:04 »

Thanks a lot, but it also doesn't work.
I am using MIDP2.0 GameCanvas.
I use Sun.com's KToolbar for testing.
I apply this method:
public void keyReleased(int keycode)
{
// switch cases
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davidaprice

Junior Devvie





« Reply #3 - Posted 2005-02-02 17:51:58 »

So just to check: your GameCanvas subclass's constructor should start with:
1  
    super(false);

That way you're not suppressing these events you want. I just hacked up one of my old games to do this, and the keyReleased method was called just as I expected.
Offline monopolyli

Senior Newbie




Java games rock!


« Reply #4 - Posted 2005-02-03 12:38:18 »

It works now, thank you very much~ Cheesy
You are very helpful~ Cheesy
However, can you tell me what is the function of
super(true) and super(false)?
Why super(false) can work but not super(true)?
Thanks a lot~ Cheesy
Offline shmoove

Junior Devvie




Doh!


« Reply #5 - Posted 2005-02-03 13:49:09 »

You use super(true) usually when you want to do all the input handling asynchroneously using the getKeyStates() method. It means that keyPressed() won't be called if a key that corresponds to one of the game actions (see David's first post) is pressed. This supposedly will make the game perform a little bit better (anyone seen proof of this by the way?) because there will be less calls to keyPressed().

shmoove
Offline monopolyli

Senior Newbie




Java games rock!


« Reply #6 - Posted 2005-02-03 14:17:31 »

I see
Thanks a lot~
Offline ribot

Junior Devvie




Ribot - mobile UI specialist


« Reply #7 - Posted 2005-02-03 21:46:22 »

I think there is little difference in performance. I always try and use the gameStates method though. At the moment, I have devised a gameCanvas that uses both methods, but only because I can't work out how to check if the fire button was pressed and the number of the button corresponds to KEY_NUM5. Any ideas guys/girls?

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline davidaprice

Junior Devvie





« Reply #8 - Posted 2005-02-04 05:55:25 »

Ribot: you question can be parsed in more than one way, so I'm not sure if I understand it correctly. If I understand the question correctly, your problem is that you're worried that the fire button might have been pressed and released between calls to getKeyStates.

But the JavaDocs for that method state that the button's bit will be set if the key is currently down or has been pressed at least once since the last time this method was called. So you won't miss any short clicks.

Unless you're targeting a particular phone for which it's true, you shouldn't assume that the fire button is (only) button 5. E.g. in Nokia Series 60 phones both button 5 and clicking the joystick work as fire buttons. Except (as usual) the 3650, where 5 probably isn't a fire button - the 3650 isn't a MIDP 2.0 phone, but still it's a good reminder that sensible assumptions aren't always true Wink. I guess also in the MIDP 2.0 Nokia 6822, 5 isn't a fire button when the folding alphanumeric keyboard is open (haven't checked). These complications are why MIDP has abstract game actions as well as key codes.
Offline ribot

Junior Devvie




Ribot - mobile UI specialist


« Reply #9 - Posted 2005-02-04 07:15:21 »

davidaprice: thank you for your response! Yes, I realise that any length of press will result in the state of the button being set to pressed until polled.  Sorry for my unobvious question, i will try to rephrase it - I'm currently working on a project which targets a specific device (Nokia 7610).  My required functionality is that when the user presses on the joystick 'fire' button, they perform an 'action'.  Want i do not want to respond to is if the fire button pressed was number 5 on the keypad (or anything else for that matter).  Is there a way of checking that the '5' or a key other than the joystick fire button was pressed so I can determine not to respond?

I hope I have made things clearer.  Wink

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davidaprice

Junior Devvie





« Reply #10 - Posted 2005-02-04 12:32:30 »

Much clearer, thanks Smiley. I'd say that the idea of game actions is handling abstract actions rather than specific keys, so if you need to distinguish between two specific keys that have the same game action, you're going to have to use key codes instead. And since GameCanvas's getKeyStates method is specified only in terms of game actions, it's no use to you in this case. So you're already doing the right thing, not suppressing the key events and using keyPressed to detect the joystick click.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!