Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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 2965 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:

case KEY_STAR:

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:
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'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:

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


« 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().

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? - design agency focused on mobile - 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 - design agency focused on mobile - 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.

Riven (24 views)
2015-07-27 16:38:00

Riven (14 views)
2015-07-27 15:35:20

Riven (19 views)
2015-07-27 12:26:13

Riven (9 views)
2015-07-27 12:23:39

BurntPizza (24 views)
2015-07-25 00:14:37

BurntPizza (36 views)
2015-07-24 22:06:39

BurntPizza (20 views)
2015-07-24 06:06:53

NoxInc (23 views)
2015-07-22 22:16:53

NoxInc (15 views)
2015-07-22 22:13:39

Jesse (36 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!