Day night cycle, cant seem to convert hex with alpha to RBGA Intager

In my render method im taking the pure RBG of the pixel, changing it to hex with a Alpha channel and then converting back but i get a error any suggestions on what im doing wrong or a better way on doing it?

int col = sheet.pixles[xSheet + ySheet * sheet.width + tileOffset];
				String hexColor = String.format("#%06X", (0xAAFFFFFF & col));
				int newCol = Integer.parseInt(hexColor.replaceFirst("#", ""), 16);

First question: why on earth would you want to do that? Is your program too fast? :persecutioncomplex:

No? tho me this is just how i thought i could make the day/night cycle work and dim the screen

So what you are actually trying to do is increase/decrease alpha?


// c is color integer, a is [0-255] alpha
private static int setAlpha(int c, int alpha) {
    return c & 0xFFFFFF & (a << 24);
}

private static int getAlpha(int c) {
    return (c >> 24) & 0xFF;
}

Yes it was, ill give the code you sent a shot now, thanks…im no good with bit placement xD


// c is color integer, a is [0-255] alpha
private static int setAlpha(int c, int alpha) {
-    return c & 0xFFFFFF & (a << 24);
+    return (c & 0xFFFFFF) | (a << 24);
}

Derp. Thanks.

Im only getting a black screen as the output, any idea? and yes i have tryed 0,255,133 etc :stuck_out_tongue: