-1
\$\begingroup\$

I am developing a game that I would like the background to be white, and it just sticks to being black. Here is my render method:

private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);

...

private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    screen.clear();
    screen.render();

    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
}

I set the graphics color to be white, which I thought that is what got it to render for the background color, but it seems not to be the problem.

I can get the screen to be white until I use g.drawImage(image, 0, 0, getWidth(), getHeight(), null), then the background turns black. There was one method in which it had the option to pick a color for it, but it didn't work. How would I get the background to be white and not black while still being able to use drawImage?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ While you're title is asking how to do something, your question is asking how to fix your code that's trying to do that thing. I've tried to clean that up for you. \$\endgroup\$
    – House
    Commented Sep 28, 2013 at 15:05

1 Answer 1

0
\$\begingroup\$

I figured it out;

For my BufferedImage, I used TYPE_INT_RGB, when I needed to use TYPE_INT_ARGB.

\$\endgroup\$
1
  • \$\begingroup\$ So the problem was not in how you were setting the background, but how you were drawing the image. Glad you got it fixed. \$\endgroup\$
    – House
    Commented Sep 28, 2013 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .