El codigo en cuestión es este:
Código:
import java.applet.Applet;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.*;
public class Map extends Applet{
public Image offscreen; /*********************/
Graphics bufferGraphics; /*********************/
private BufferedImage arena, cesped; /*********************/
private String[] map; /*Declaración de vars*/
private int i, j; /*********************/
int col = 15, fil = 32; /*********************/
public void init(){ /*********************/
String map[]={
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /* INDICE DEL MAPA */
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXYYYYYYYYYYYYYYYYYXXXXXXX", /********************/
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", /********************/
};
checkimg();
setSize(800, 600);
offscreen = createImage(800, 600); //Doble buffer...
bufferGraphics = offscreen.getGraphics();
}
private void checkimg(){
try{
arena = ImageIO.read(getClass().getClassLoader().getResource("sandtile.png"));
cesped = ImageIO.read(getClass().getClassLoader().getResource("tileground1.png"));
}catch(Exception ex){
System.out.println("Imposible to get the images"); // Nunca me ha saltado el error aqui y la funcion la llamo desde el init(), asi que las carga bien.
System.out.println(ex);
}
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
bufferGraphics.setColor(Color.black); // Fondo para el buffer
bufferGraphics.fillRect(0, 0, 800, 600); // Fondo para le buffer
for (j = 0; i < 15; j++){
for (i = 0; i < 32; i++){
if(map[j].charAt(i) == 'X'){ // <-- En esta linea me salta error en la consola pero no me subraya nada :(
bufferGraphics.drawImage(cesped, j*32, i*32, this);
}
if(map[j].charAt(i) == 'Y'){
bufferGraphics.drawImage(arena, j*32, i*32, this);
}
}
}
g.drawImage(offscreen, 0, 0, this); // Dibujo del offscreen del doble buffer para evitar flash
}
}
El error me salta desde la consola y me señala esta linea --- > if(map[j].charAt(i) == 'X')" <----- pero solo me salta al iniciar el debug el editor de eclipse no me subraya nada. Las imagenes me las carga bien. Alguien sabe que ocurre??