Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Game programming with J2ME Polish

Optimize J2ME Polish's game engine

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

The games industry is the biggest player in the J2ME market. When you're programming J2ME applications, chances are that you are working on games. Gaming is a tremendous success story for mobile Java and belongs to the "3 Gs" that supposedly form the main revenues in the mobile arena: games, gambling, and girls. The gaming market is growing rapidly and has an estimated volume of billion worldwide in 2005.

The industry has reacted by introducing great enhancements for game programming in the Mobile Information Device Profile 2.0 standard through the Java Community Process Website. Unfortunately, the majority of phones out there support only the MIDP 1.0 standard. This is where J2ME Polish's game engine comes to the rescue. As you'll learn in this chapter, you can use the game engine of J2ME Polish for quickly porting MIDP 2.0 games to MIDP 1.0 platforms.

Using the game engine

Programming games using the MIDP 2.0 game API is easy. You have sprites, a layer manager with a view window, and much more. These features are sorely missed when you develop your game for MIDP 1.0 platforms. This is why J2ME Polish includes a wrapper API that enables you to use the javax.microedition.lcdui.game.* API, even on MIDP 1.0 devices. The game engine allows you to use the complete MIDP 2.0 game API on MIDP 1.0 devices. Usually, no source code changes are necessary when you use proper import statements. However, there are some principal restrictions that might require adjustments of your code, especially the inability to use the pixel-level collision detection. Also, not all MIDP 1.0 platforms support sprite transformations. Dealing with these limitations is discussed in the "Working around the Limitations of the Game Engine" section later in this article.

Using the game engine is not difficult. J2ME Polish weaves the wrapper classes in your code automatically when you target MIDP 1.0 devices. This is done just by exchanging the import statements, so you must use proper import statements instead of fully qualified class names. Listing 1 demonstrates what you should not do.

Listing 1. How not to use the game engine

 public class MyGameCanvas
extends javax.microedition.lcdui.game.GameCanvas
implements Runnable
{
   public MyGameCanvas(boolean supress) {
      super(supress);
   }

public void run() { // main game-loop } }


The code in Listing 1 won't work when you target a MIDP 1.0 device. Listing 2 shows a working example, which uses import statements properly.

Listing 2. Proper use of the game engine with import statements

 import javax.microedition.lcdui.game.GameCanvas;
public class MyGameCanvas
extends GameCanvas
implements Runnable
{
   public MyGameCanvas(boolean supress) {
      super(supress);
   }

public void run() { // main game-loop } }


Optimizing the game engine

You can tweak the game engine by defining several preprocessing variables in the <variables> section of your build.xml script. The following optimizations are available:

  • Enable the full-screen mode for your game
  • Optimize the performance of the TiledLayer by using a back buffer and/or single tile images
  • Increase the number of possible tiles
  • Activate the game engine for MIDP 2.0 devices with a faulty or slow implementation of the game API

Running your game in full-screen mode

Usually, you will want to use the full-screen mode for your game. To enable this mode, use the fullscreen attribute of the <build> element in your project's build.xml file. Possible values are true, false, or menu. The menu mode allows you to design the menu bar, but it is available only when you use the J2ME Polish GUI.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (1)
Login
Forgot your account info?

good newsBy Anonymous on February 20, 2009, 7:42 amthe web site is wonderful and i appriciate it.

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources