Hi, I started to develop some games, and my first deployment on a real device (Nokia 3650/firmware: 2.54) doesn't works.
I cut and paste the "Your First Micro Java Game (http://www.onjava.com/pub/a/onjava/2.../javagame.html)", tested on latest emulators (Nokia NDS and J2ME WTK 2.0), works well. When transfered to 3650, launch the MIDlet, a blank screen is showed and got back to Applications folder. An interesting thing is if I change the getWidth/getHeight in SpaceCanvas by 176 and 144 (canvas size) all works well. I don't think is a Canvas bug, but this problem are taking hard for me to solve it.
The code is really simple but this problem is shaking my head. I think JAD, manifest and .java files are fine. Below is the code:
package claudius;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class SpaceGame extends MIDlet implements CommandListener {
// The main display elements
private Display theDisplay;
private SpaceCanvas canvas;
// The exit command, so we can end the game
static final Command exitCommand = new Command("Exit", Command.STOP, 1);
public SpaceGame() {
// Create the main Display
theDisplay = Display.getDisplay(this);
}
class SpaceCanvas extends Canvas {
private Sprite shipSprite;
private int width;
private int height;
SpaceCanvas() {
//width = getWidth();
//height = getHeight();
width = 176;
height = 144;
// Load the graphics
Image spaceship = null;
try {
spaceship = Image.createImage("/spaceship.png");
shipSprite = new Sprite(spaceship);
// Put the sprite at (0,50)
shipSprite.setX(0);
shipSprite.setY(50);
} catch (Exception ioe) {
System.err.println("Problem loading image " + ioe);
}
}
public void paint(Graphics g) {
// Paint a white background
g.setColor(255, 255, 255);
g.fillRect(0, 0, width, height);
g.setColor(255, 255, 255);
// Paint the sprite
shipSprite.paint(g);
}
public void keyPressed(int keyCode) {
int key = getGameAction(keyCode);
// Move the sprite left or right.
if (key == LEFT) {
int newx = shipSprite.getX() - 5;
if (newx < 0)
newx = 0;
shipSprite.setX(newx);
} else if (key == RIGHT) {
int newx = shipSprite.getX() + 5;
if (newx > (width - 10))
newx = (width - 10);
shipSprite.setX(newx);
}
// Repaint the canvas!
repaint();
}
}
protected void startApp() throws MIDletStateChangeException {
canvas = new SpaceCanvas();
// Add the exit command
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
theDisplay.setCurrent(canvas);
}
protected void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
// Handle events
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
////////
Sprite paint:
public void paint(Graphics g) {
g.drawImage(image, x, y, Graphics.TOP | Graphics.LEFT);
}
If you have any tip, I will apreciate.
Thanks
Claudio

Reply With Quote

