Caros,
Estou em apuros com esse código e só vocês pra me salvarem… A ideia aqui é simples: Um jogo com mapa em TiledLayer e 1 ou 2 sprites pra fazer movimento de personagens. Ocorre que o MIDlet já se inicia em tela branca e eu não acho o erro por nada no mundo.
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
/**
*
-
@author d3monz
*/
import javax.microedition.lcdui.;
import javax.microedition.lcdui.game.;
public class Figura extends GameCanvas implements Runnable {
private LayerManager lm;
private Sprite s,s1;
private Image mega, megaHit, blocos;
private TiledLayer tl;
private boolean movimentar = true;
private int x = 30, y = 30;
public Figura() {
super(true);
lm = new LayerManager();
try {
mega = Image.createImage("megaman_walk.png");
megaHit = Image.createImage("megaman_hit.png");
blocos = Image.createImage("blocos.png");
s = new Sprite(mega,40,46);
s1 = new Sprite(megaHit,42,68);
tl = new TiledLayer(5, 5, blocos, 16, 16);
int[] mapa = {1,1,1,1,1,
0,0,0,0,0,
12,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0};
for (int i = 0; i< mapa.length; i++) {
int linha = i/5;
int coluna = i%5;
tl.setCell(coluna, linha, mapa[i]);
}
lm.append(s);
lm.append(s1);
lm.append(tl);
Thread t = new Thread(this);
t.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void desenhar(Graphics g) {
g.setColor(0, 0, 0);
g.fillRect(0, 0, getWidth(),getHeight());
s.setPosition(x, y);
lm.paint(g, 0, 0);
flushGraphics();
}
public void escuta() {
int key = getKeyStates(), imov = 11;
switch (key) {
case LEFT_PRESSED:
imov--;
x--;
s.setFrame(imov);
if (imov == 0) {
imov = 10;
}
break;
case RIGHT_PRESSED:
imov++;
x++;
s.setFrame(imov);
if (imov == 22) {
imov = 11;
}
break;
}
}
public void run() {
Graphics g = getGraphics();
while(movimentar) {
escuta();
desenhar(g);
try {
Thread.sleep(30);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
[/code]
Alguém tem ideia do que possa ser?
