Home E-Books J2ME Game Development: Issues and Troubleshooting Devices and canvas

J2ME Game Development: Issues and Troubleshooting(TM) - Devices and canvas

by Massimo Perrone (Hanami Solutions)

1.2 Devices and canvas

I'll provide an example fitting the first category. Mobiles falling in the first classification range from a minimum of 96*51 for the Motorola v60i to a maximum of 101*64 for the Siemens M50 and C55. It will be better then to opt for a 96*51 version that will be centered every time on the screen of each different device.

 

1.3 Screen centering

How can we manage to center pictures shown on screen no matter what his dimensions are?

It's really simple; take a look at the following code to be used during the initialization of the class we will use as canvas:

width = 96;
height = 51;              

realw = getWidth();.
realh = getHeight();.
                
moveW=(realw-width)>>1;
moveH=(realh-height)>>1;  

With the first two variables we will set dimensions of the image shown on screen (to be more exact it will be width and height of the version we've chosen, that is 96*51); with the second pair of them we fetch the real size of device screen we're working on and at last we calc the gap between its real size and the one we set.

Now we can use values of the gaps with method paint() at time of drawing graphics on screen as follow:

g.drawImage(offImage,moveW,moveH,g.TOP|g.LEFT);

and be sure to have it centered on any device when drawn on screen.

In this case screen size may vary only a few pixels between a device and another so the centering effect grants an excellent solution that will allow easy and quick mantainance of future software revisions.

What to do instead when devices have noticeable differences that would require broad black (or white) lateral bands and/or on top and bottom of the screen? Be that the case one would need to fit user's needs while trying to not twist code and internal working of our version.

This applies e.g. to the second category:

  • 2) Nokia 7210, Nokia 6610, Sharp Gx10, Samsung T100 and Motorola T720.
  • These devices are quite different from each other and their screen size ranges from 128*96 up to 128*144 with some odd ones in between like Sharp Gx10's 120*130. How can we solve this? First of all let's try to find a new standard resolution, given the current situation we will opt for 120*96.

    This will solve the problem only in part, indeed on some devices while the horizontal gap will result acceptable, the vertical gap will still be unacceptable.

    A great solution, we adopted it too, is to retrieve, by mean of the aforementioned function getHeight(), height of the device and if this is higher than a given value we will draw addictional graphics below and above the one already centered on screen. Simple, isn't?

    Next Page >>