I just added an option to my game that makes it so that all the enemies will have a random color for their clothes instead of the regular blue. I use this code to draw rectangles over the shirt of the enemy.
BufferedImage image = new BufferedImage(z.getWidth(), z.getHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
try{
image = ImageIO.read(new File("C:\\Program Files (x86)\\ZombieGame\\
Zombie.png"));
}catch (IOException ex) {
}
int j, k, red, green, blue;
for(j = 0; j < z.getWidth(); j++){
for(k = 0; k < z.getHeight(); k++){
Color c = new Color(image.getRGB(j, k));
red = c.getRed();
green = c.getGreen();
blue = c.getBlue();
if(red == 0 && green == 0 && blue == 178){
g2d.setColor(Color.red);
Rectangle r = new Rectangle(j,k, 1, 1);
Path2D.Double rect = new Path2D.Double(r, at);
g2d.fill(rect);
}
}
}
The thing is that when I apply this the game will run twice as slow (before I added this code I got a solid 80 fps but as fast as I added it I got around 30 fps). Is there a better way in which I could change the color of specific parts of the image without lowering the fps drastically?
C:\Program Files (x86)\ZombieGame
is a bad idea. \$\endgroup\$