Je souhaite qu'une image-objet monochrome 16 x 16 soit affichée sur mon écran. Le sprite a 8 nuances différentes, qui correspondent à 8 couleurs différentes. Chaque couleur peut avoir sa propre ombre aussi, mais je veux limiter ce à 8. Ainsi, au lieu de FF00FF, je veux que ce soit comme 707.Sprite de rendu de 8 couleurs monochromes
J'ai le projet sur github
Ce que je « ai jusqu'à présent est la suivante:
C'est là que je crée toutes les couleurs possibles:
int[] colours = new int[8 * 8 * 8];
int index = 0;
for(int r = 0; r < 8; r++) {
for(int g = 0; g < 8; g++) {
for(int b = 0; b < 8; b++) {
int rr = r * 255/7;
int gg = g * 255/7;
int bb = b * 255/7;
colours[index++] = rr << 16 | gg << 8 | bb;
}
}
}
C'est là que je veux appeler un long int contenant toutes les informations de couleur:
public class Colours {
public static int get(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8) {
//bit shifting with 56 on an integer removes data
return((get(c8) << 28) + (get(c7) << 24) + (get(c6) << 20) + (get(c5) >> 16) +
(get(c4) << 12) + (get(c3) << 8) + (get(c2) << 4) + (get(c1)));
}
private static int get(int colour) {
if(colour < 0) {
return 255;
}
int r = colour/100 % 10;
int g = colour/10 % 10;
int b = colour % 10;
return r * 64 + g * 8 + b;
}
}
C'est là que l'écran est rendu:
public void render(int xPos, int yPos, int tile, int colour) {
xPos -= xOffset;
yPos -= yOffset;
int xTile = tile % 32;
int yTile = tile/32;
int tileOffset = (xTile << 4) + (yTile << 4) * sheet.width;
for (int y = 0; y < 16; y++) {
if (y + yPos < 0 || y + yPos >= height) {
continue;
}
int ySheet = y;
for (int x = 0; x < 16; x++) {
if (x + xPos < 0 || x + xPos >= width) {
continue;
}
int xSheet = x;
int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 16)) & 255;
if (col < 255) {
pixels[(x + xPos) + (y + yPos) * width] = col;
}
}
}
}