Java - ayuda cdel MIDlet

 
Vista:

ayuda cdel MIDlet

Publicado por aitor (85 intervenciones) el 18/05/2010 22:05:36
el problema que tengo es que tengo es que al ejecutar la aplicacion para el movil no me muestra el mapa "pantalla". pantalla contiene un papa de un juego y un sprite llamado miSprite. el programa no da errores.

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* @author Aitor
*/
public class juego extends MIDlet implements CommandListener {

private boolean midletPaused = false;
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
private Command exitCommand;
private Form form;
private StringItem stringItem;
//</editor-fold>
private SSCanvas pantalla;

public juego() {
}



private void initialize() {

}

public void resumeMIDlet() {

}

public void switchDisplayable(Alert alert, Displayable nextDisplayable) {

Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}

}

public void commandAction(Command command, Displayable displayable) {

if (displayable == form) {
if (command == exitCommand) {

exitMIDlet();

}
}

}

public Command getExitCommand() {
if (exitCommand == null) {
exitCommand = new Command("Exit", Command.EXIT, 0);
}
return exitCommand;
}

public Form getForm() {
if (form == null) {
// write pre-init user code here
form = new Form("Welcome", new Item[] { getStringItem() });
form.addCommand(getExitCommand());
form.setCommandListener(this);
// write post-init user code here
}
return form;
}

public StringItem getStringItem() {
if (stringItem == null) {

stringItem = new StringItem("Hello", "Hello, World!");

}
return stringItem;
}

public Display getDisplay() {
return Display.getDisplay(this);
}

public void exitMIDlet() {
switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}

public void startApp() {
if (midletPaused) {
resumeMIDlet();
} else {
initialize();

pantalla = new SSCanvas();

new Thread(pantalla).start();
Display d = this.getDisplay();

}
midletPaused = false;
}

public void pauseApp() {
midletPaused = true;
}

public void destroyApp(boolean unconditional) {
}

class SSCanvas extends Canvas implements Runnable {

private Sprite miSprite = new Sprite(1);
private Sprite [] tile=new Sprite[5];
private int sleepTime, indice_in,indice, xTiles,yTiles;
private int deltaX;
private int deltaY;
private int map[]={ 1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,2,1,1,1,1,1,
1,1,1,4,1,1,1,
1,1,1,1,1,1,1,
1,1,3,1,2,1,1,
1,1,1,1,1,1,1,
1,4,1,1,1,1,1,
1,1,1,1,3,1,1,
1,1,1,1,1,1,1,
1,4,1,1,1,1,1,
1,1,1,3,1,1,1,
1,1,1,1,1,1,1,
1,1,1,1,1,1,1,
1,2,1,1,1,1,1,
1,1,1,4,1,1,1,
1,1,1,1,1,1,1,
1,1,3,1,2,1,1,
1,1,1,1,1,1,1,
1,4,1,1,1,1,1};

public SSCanvas() {

this.miSprite.addFrame(1, "imagenes/avion.png");

this.miSprite.on();

}

public void paint(Graphics g) {

int x=0, y=0, t=0;
int i, j;

g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());

for(i=0;i<yTiles;i++){
for(j=0;j<xTiles;j++){

t=map[this.indice+(i*xTiles+j)];
x=j*32;
y=(i-1)*32+this.indice_in;

this.tile[t].setX(x);
this.tile[t].setY(y);
this.tile[t].draw(g);

}
}
this.miSprite.setX(miSprite.getX());
this.miSprite.setY(miSprite.getY());
this.miSprite.draw(g);
}

public void keyReleased(int keyCode) {

int action = getGameAction(keyCode);

switch (action) {

case LEFT:
this.deltaX = 0;
break;

case RIGHT:
this.deltaX = 0;
break;

case UP:
this.deltaY = 0;
break;

case DOWN:
this.deltaY = 0;
break;

}

}

public void keyPressed(int keyCode) {

int action = getGameAction(keyCode);

switch (action) {

case LEFT:
this.deltaX = -5;
break;

case RIGHT:
this.deltaX = 5;
break;

case UP:
this.deltaX = -5;
break;

case DOWN:
this.deltaX = 5;
break;
}
}

public void run() {

iniciar();

while (true) {
doScroll();
computePlayer();
repaint();
serviceRepaints();

try {
Thread.sleep(sleepTime);
} catch (InterruptedException ex) {
ex.printStackTrace();
}

}
}

private void iniciar() {

int i;

this.sleepTime=50;
this.miSprite.setX(this.getWidth()/2);
this.miSprite.setY(this.getHeight()-20);
this.deltaX=0;
this.deltaY=0;
this.xTiles=7;
this.yTiles=8;
this.indice=this.map.length-(xTiles*yTiles);
this.indice_in=0;

//iniciamos los tiles
for(i=1;i<=4;i++){
this.tile[i]=new Sprite(1);
this.tile[i].on();

}
this.tile[1].addFrame(1, "imagenes/image32.png");
this.tile[2].addFrame(1, "imagenes/image33.png");
this.tile[3].addFrame(1, "imagenes/image34.png");
this.tile[4].addFrame(1, "imagenes/image33.png");


}

private void computePlayer() {

if (miSprite.getX() + deltaX > 0 && miSprite.getX() + deltaX < getWidth() && miSprite.getY() + deltaY > 0 && miSprite.getY() + deltaY < getHeight()) {

miSprite.setX(miSprite.getX() + deltaX);
miSprite.setY(miSprite.getY() + deltaY);

}
}

private void doScroll() {

this.indice_in+=2;
if(this.indice_in>=32){
this.indice_in=0;
this.indice-=xTiles;
}

if(this.indice<=0){

//si llegamos al final, empezamos de nuevo
this.indice=this.map.length-(xTiles*yTiles);
this.indice_in=0;
}
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder