Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GameCanvas Keys

 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
These days I am studying the Game API of MIDP 2.0. I have some questions. In the API the DOWN_PRESSED key is explained as this,
DOWN_PRESSED
Declaration:
public static final int DOWN_PRESSED
Description:
The bit representing the DOWN key. This constant has a value of 0x0040 (1 << Canvas.DOWN).[
.
I don't understand what they mean by 1 << Canvas.DOWN.
In there example they use this kind of a code snippet.


What does this keyState & LEFT_PRESSED mean? Could you please explain this to me, Thanks a lot in advance.
 
Satyam Kothapally
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>0x0040(1<<Canvas.DOWN)

Canvas.DOWN has a constant value 6. so left shifting 1 six times gives 64 which is equal to 0x0040.

> if((keyState & DOWN_PRESSED) !=0) ?

When a particular key is pressed down the appropriate bits in the keyState interger are set to 1's. So when you logically AND the keyState with DOWN_PRESSED when the down key is pressed it will return a non-zero value.


Hope this helps...

Satyam Kothapally.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot for the reply, I think I got it, first answer is so clear now, but this keyStates method is not that very clear, hope you can explain about the integer what it returns. Does it return a binary string? regards
 
Satyam Kothapally
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getKeyStates() returns an integer which is represented as a 32 bit long, 2's complement binary number in java.

So when physical keys are pressed after the last call to getKeyStates() method, bits corresponding to the actual keys pressed are set. Thus when we logically AND(&) (the binary numbers represented by the) interger returned by getKeyStates() method and the constant integers defined for various keys in GameCanvas we would know (from the result of logical ANDing) what all keys were pressed since the last call.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot for the answer, its is so clear now, BTW I am planning to do the exam with in 3 weeks, can I have your yahoo ID if possible, so that I can discuss a bit about the exam with you, thanks a lot, regards
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ransika deSilva:
BTW I am planning to do the exam with in 3 weeks


Ransika, finally, you registered it. All the best for the exam. Great Success follows Hard work. I do believe that you will do well in the exam.
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ko ko,

Many thanks for your wishes. Yes I paid for the exam and its a matter of doing the exam. I am sure I have to work a lot more though cause I missed out studying for the past one week or so. Hope I would get your help if I need it. Thanks a lot and wish you all the best for your studies (SCJA).
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ransika deSilva:
Hope I would get your help if I need it.

Of course, I'll be around here some time.

Thanks a lot and wish you all the best for your studies (SCJA).

I already sat for the exam... I just forgot to change my status down in my signature. Thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic