I'm making a game but I'm still in the screen-making proces . I've made a spritesheet with black, dark gray, light gray, and white colors and I want to make them bright colors, but I get an ArryIndexOutOfBoundsExeption when I try to initialize the first color.
this is my code for the class where I want help with:
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_MASK];
public int[] colours = new int[MAP_WIDTH * MAP_WIDTH_MASK * 4];
public int xOffset = 0;
public int yOffset = 0;
public int width;
public int height;
public SpriteSheet sheet;
public Screen(int width, int height, SpriteSheet sheet){
this.width = width;
this.height = height;
this.sheet = sheet;
for(int i = 0; i < MAP_WIDTH * MAP_WIDTH; i++ ){
colours[i*4+0] = 0xff00ff;
colours[i*4+1] = 0x00ffff;
colours[i*4+2] = 0xffff00;
colours[i*4+3] = 0xffffff;
}
}
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 - yOffset;
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];
}
}
}
}
}
If someone knows how to fix the problem so that the exeption is gone, feel free to reply ;)