Estou com um problema com um codigo de Java Exception in thread "Thread-0" java.lang.ArrayIndexOutOfBoundsException: Index -44 out of bounds for length 400 at com.adroid.world.World.render(World.java:69) at com.adroid.main.Game.render(Game.java:105) at

o erro é esse
Exception in thread “Thread-0” java.lang.ArrayIndexOutOfBoundsException: Index -44 out of bounds for length 400
at com.adroid.world.World.render(World.java:69)
at com.adroid.main.Game.render(Game.java:105)
at com.adroid.main.Game.run(Game.java:130)
at java.base/java.lang.Thread.run(Thread.java:831)

public class World {
	
	private Tile[] tiles;
	public static int WIDTH, HEIGHT;
	
	public World(String path) {
		try {
			BufferedImage map = ImageIO.read(getClass().getResource(path));
			int[] pixels = new int[map.getWidth() * map.getHeight()];
			WIDTH = map.getWidth();
			HEIGHT = map.getHeight();
			tiles = new Tile[map.getWidth() * map.getHeight()];
			map.getRGB(0, 0, map.getWidth(), map.getHeight(), pixels, 0, map.getWidth());
			for(int xx = 0; xx < map.getWidth(); xx++) {
				for(int yy = 0; yy < map.getHeight(); yy++) {
					int pixelAtual = pixels[xx + (yy*map.getWidth())];
					tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_FLOOR);
					if(pixelAtual == 0xFF000000) {
						//Floor/Chão
						tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_FLOOR);
					}else if(pixelAtual == 0xFFFFFFFF) {
						//Parede
						tiles[xx + (yy*WIDTH)] = new FloorTile(xx*16,yy*16,Tile.TILE_WALL);
					}else if(pixelAtual == 0xFF0026FF) {
						//Player
						Game.player.setX(xx*16);
						Game.player.setY(yy*16);
					}else if (pixelAtual == 0xFFFF0000) {
						//Enemy
						Game.entities.add(new Enemy(xx*16,yy*16,16,16, Entity.ENEMY_EN));
					}else if (pixelAtual == 0xFFFFD73A) {
						//Weapon
						Game.entities.add(new Weapon(xx*16,yy*16,16,16, Entity.WEAPON_EN));
					}else if (pixelAtual == 0xFF808080) {
						//Life Pack
						Game.entities.add(new LifePack(xx*16,yy*16,16,16, Entity.LIFEPECK_EN));
					}
					else if (pixelAtual == 0xFFFFD800) {
						//Bullet
						Game.entities.add(new Bullets(xx*16,yy*16,16,16, Entity.BULLET_EN));
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void render(Graphics g) {
		int xstart = Camera.x/16;
		int ystart = Camera.y/16;
		
		int xfinal = xstart + (Game.WIDTH / 16);
		int yfinal = ystart + (Game.HEIGHT / 16);
		
		for(int xx = xstart; xx <= xfinal; xx++) {
			for(int yy = ystart; yy <= yfinal; yy++) {
				Tile tile = tiles[xx + (yy*WIDTH)];
				tile.render(g);
			}
		}
	}
}

Quase todo ano alguém tem problema nesse mesmo fonte, é algum curso?

Dá uma olhada neste tópico.

1 curtida