Domanda

The weirdest thing is happening, and I can't figure it out. I am making a StateBasedGame, and in one of the BasicGameStates, I'm trying to draw an image. It shows up white, though. Code:

@Override
    public void render(GameContainer arg0, StateBasedGame arg1,
            Graphics g) throws SlickException {
        // TODO Auto-generated method stub
        g.setBackground(Color.blue);
        Image image = new Image("res/Sniper Scope (Border).png");
        g.drawImage(image, 230,100);
    }

It seems to be finding the image (it doesn't crash), but all that comes up is this:

Any help would be greatly appreciated.

È stato utile?

Soluzione

Move your image initialization/declaration into the init method. If you wish to call the image in the render scope, you should have the image set to be a global variable, then initialize it in the Init method.

Edit: also, image classes in slick have draw(x, y) methods available! So no need for g.drawImage(). Example: Image img = New Image("res/Image.png");

Render method: img.draw(0, 0);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top