public void render(int xp, int yp, int tile, int colors, int bits) {
xp -= xOffset;
yp -= yOffset;
boolean mirrorX = (bits & BIT_MIRROR_X) > 0;
boolean mirrorY = (bits & BIT_MIRROR_Y) > 0;
int xTile = tile % 32;
int yTile = tile / 32;
int toffs = xTile * 8 + yTile * 8 * sheet.width;
for (int y = 0; y < 8; y++) {
int ys = y;
if (mirrorY) ys = 7 - y;
if (y + yp < 0 || y + yp >= h) continue;
for (int x = 0; x < 8; x++) {
if (x + xp < 0 || x + xp >= w) continue;
int xs = x;
if (mirrorX) xs = 7 - x;
int col = (colors >> (sheet.pixels[xs + ys * sheet.width + toffs] * 8)) & 255;
if (col < 255) pixels[(x + xp) + (y + yp) * w] = col;
}
}
}
我按照 youtube 上的教程创建了该方法,但它仅渲染精灵表中 8x8 的图块。我想让它渲染 32x32 的图块,但是当我将其更改为所有 8 到 32 时,如下所示:
public void render(int xp, int yp, int tile, int colors, int bits) {
xp -= xOffset;
yp -= yOffset;
boolean mirrorX = (bits & BIT_MIRROR_X) > 0;
boolean mirrorY = (bits & BIT_MIRROR_Y) > 0;
int xTile = tile % 32;
int yTile = tile / 32;
int toffs = xTile * 32 + yTile * 32 * sheet.width;
for (int y = 0; y < 32; y++) {
int ys = y;
if (mirrorY) ys = 7 - y;
if (y + yp < 0 || y + yp >= h) continue;
for (int x = 0; x < 32; x++) {
if (x + xp < 0 || x + xp >= w) continue;
int xs = x;
if (mirrorX) xs = 7 - x;
int col = (colors >> (sheet.pixels[xs + ys * sheet.width + toffs] * 32)) & 255;
if (col < 255) pixels[(x + xp) + (y + yp) * w] = col;
}
}
}
它给了我一个错误说:
Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: -1184
at orbis.src.Screen.render(Screen.java:79)
at orbis.src.TileWater.render(TileWater.java:37)
at orbis.src.World.renderBackground(World.java:143)
at plixel.orbis.Orbis.render(Orbis.java:383)
at plixel.orbis.Orbis.run(Orbis.java:297)
at java.lang.Thread.run(Unknown Source)