June 23, 2024

Messing with J2ME MIDP 2.0

MIDP 2.0 has some intresting additions, namely for me the most intresting being the game api it introduces. It adds 'layers' and and a special GameCanvas, layers being objects that know how to draw themselfs and can be placed on a LayerManager for easy drawing of them all at the same time. It also offers collision detection(pixel perfect or rectangle overlap) between these different layers. One of them that could be of most use is the TiledLayer which makes drawing a simple 2d game map a breeze.

But, these are not currently so perfectly adopted in the vm's, for example if you got a nicely sized(200*200 and more tiles) maps using TiledLayer gets extremely slow, even if it could see that there's no need to draw the entire layer at any point in time(viewWindow is only set to a small area at a time). So this means that in certain types of games using a TiledLayer is not really possible when considering the benefits of using your own code for drawing the thing(no speed hit from the level being big big big) even if you still used TiledLayer for collision checks and functions like that.

Another nice additions is the possibility to poll for the keystates in GameCanvas so there's no need anymore to keep track of the keys by yourself. However, this doesn't really give you real performance advantage(as suggested somewhere, I forget where), it's just a handy helper tool.

All and all even if the new classes do make it easier for hardware manufacturers to optimize their VM's so that these operations can be done in native code and appear super fast - that doesn't seem to be the case yet, sadly. Also they are rather limiting on what you can do with them, and too slow to use them 'creatively' at this point still(for doing an isometric/multi level engine with them for example).

Of other Canvas related things there's setFullScreenMode which can be used to change the canvas to take the whole screen, previously on nokias one would need to use nokias FullCanvas to get this(again, this is just one of those things that saves a little bit of work, also you couldn't add Commands into FullCanvas, and you generally needed some extra wrap code if you wanted that the midlet would work on nokias with the FullCanvas and when not on nokias it would revert back to normal Canvas).

However, I must still say that J2ME toolkits and devchains are so much better than the symbian developer tools that it's a joy to write... now if only even I had a MIDP 2.0 phone.

Posted by glass at June 23, 2024 04:02 PM
Good to see it confirmed that TiledLayer seems to be VERY slow when dealing with large maps. I thought something was wrong with my test code, as it hang when doing a set of 100x100 tiles (tilesize 32 pixels) and barerly runs when I'm down to something like 10x10. Posted by: René at July 3, 2024 05:50 PM
Hey thanx a lot for the info on Full Canvas.Was contemplating on what to actually do. But your article got me to decide to stick on to MIDP2.0 thanx AGAIN Posted by: bituThomas at July 5, 2024 12:41 PM
Great post. Thanks! Posted by: cd duplication at August 12, 2024 06:11 AM
Post a comment

Remember personal info?