我收到一个奇怪的错误,我不确定为什么有人能发现错误在哪里?
错误:
Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: -61
at ca.serict.game.gfx.Screen.render(Screen.java:55)
at ca.serict.game.entities.Player.render(Player.java:57)
at ca.serict.game.level.Level.renderEntities(Level.java:67)
at ca.serict.game.Game.render(Game.java:168)
at ca.serict.game.Game.run(Game.java:127)
at java.lang.Thread.run(Unknown Source)
如果您需要从这些行中的任何一行查看代码,则会列出错误,请告诉我。
Screen.java 第 55 行:
int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 8)) & 255;
Player.java 第 57 行:
screen.render(xOffset, + modifier, yOffset, (xTile + 1) + yTile * 32, colour);
Level.java 第 65 - 69 行:
public void renderEntities(Screen screen) {
for (Entity e : entities) {
e.render(screen);
}
}
Game.java 第 168 行:
level.renderEntities(screen);
Game.java 第 157 - 128 行:
if (shouldRender) {
frames++;
render();
}
屏幕 55 的公共无效:
public void render(int xPos, int yPos, int tile, int colour, int mirrorDir) {
xPos -= xOffset;
yPos -= yOffset;
boolean mirrorX = (mirrorDir & BIT_MIRROR_X) > 0;
boolean mirrorY = (mirrorDir & BIT_MIRROR_Y) > 0;
int xTile = tile % 32;
int yTile = tile / 32;
int tileOffset = (xTile << 3) + (yTile << 3) * sheet.width;
for (int y = 0; y < 8; y++) {
if (y + yPos < -0 || y + yPos >= height)
continue;
int ySheet = y;
if (mirrorY)
ySheet = 7 - y;
for (int x = 0; x < 8; x++) {
if (x + xPos < -0 || x + xPos >= width)
continue;
int xSheet = x;
if (mirrorX)
xSheet = 7 - x;
int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 8)) & 255;
if (col < 255)
pixels[(x + xPos) + (y + yPos) * width] = col;
}
}
}