how to implement the trackball function in Canvas?(left, right, up, down, click)

asuna's picture

hello:

I met this problem when I wanted to run my program on 8100. My application does not use a Screen but a Canvas. In the simulator help, it says the imput fuction is

TrackballPress
Press the trackball

TrackballRelease
Release the trackball

TrackballRoll( int x-delta, int y-delta )
Move the trackball

but I didn't find this 3 methods anywhere.

If I want to use the Canvas, which interface and methods should I use?

Is there anyone help me? Thanks a lot.

Trackback URL for this post:

http://blackberry.developercommunity.com/trackback/294

Even tho it is discouraged by RIM, you could try to use a "TrackwheelListener" which provides trackwheelClick, trackwheelUnclick and trackwheelRoll, which should do what you need.

asuna's picture

Thanks. But how can I implement the left and right function ? That's the most important thing for me.

The Documentation says:
The parameter amount is
negative for a upwards roll, and positive for a downwards roll. 

The "status" variable should have one state when you roll downwards or upwards and another state, when you roll left or right...

All you need to know is, which value status has, when you roll left and right and then check for that.

asuna's picture

Thanks for your help.

I try to print out the "status" but either I roll flatly or vertically, it returns 0. By the way, I don't have a device so i test this on the simulator. Does this matter?

 

in Canvas use

void keyPRessed(int keyCode)

{

  int gameACtion = getGameAction(keyCode);

  if (gameAction == Canvas.UP) { // move up or right

  if (gameAction == Canvas.DOWN) { // move left or down

 

  if (gameAction == 0) { // trackwheel click

asuna's picture

Thanks for your help!

It seems work well~