我真的对这种方法感到困惑,主要是因为我很困惑为什么他在某些部分会发生位移。
我不知道为什么要使用地图宽度蒙版或这里的任何东西都如此令人困惑,有人可以为我剖析这一切吗?
public static final int MAP_WIDTH = 64;
public static final int MAP_WIDTH_MASK = MAP_WIDTH - 1;
public int[] tiles = new int[MAP_WIDTH * MAP_WIDTH];
public int[] colours = new int[MAP_WIDTH * MAP_WIDTH * 4];
public int xOffSet = 0;
public int yOffSet = 0;
public int width;
public int height;
public void render(int[] pixels, int offset, int row) {
for(int yTile = yOffSet >> 3; yTile <= (yOffSet +height) >> 3; yTile++) {
int yMin = yTile * 8 - yOffSet;
int yMax = yMin + 8;
if(yMin <0) yMin = 0;
if(yMax > height) yMax = height;
for(int xTile = xOffSet >> 3; xTile <= (xOffSet + width) >> 3; xTile++) {
int xMin = xTile * 8 - xOffSet;
int xMax = xMin + 8;
if(xMin <0) xMin = 0;
if(xMax > width) xMax = width;
int tileIndex = (xTile & (MAP_WIDTH_MASK)) + (yTile & (MAP_WIDTH_MASK)) * MAP_WIDTH;
for(int y= yMin; y<yMax; y++) {
int sheetPixel = ((y + yOffSet) & 7) * sheet.width + ((xMin + xOffSet) & 7 );
int tilePixel = offset + xMin + y * row;
for(int x = xMin; x < xMax; x++) {
int colour = tileIndex * 4 + sheet.pixels[sheetPixel++];
pixels[tilePixel++] = colours[colour];
}
}
}
}
}