3

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.

John Farkerson
  • 2,543
  • 2
  • 23
  • 33
  • This is improper use of the render method used in slick. Rule of thumb is to never declare/initialize variables (especially images, as there won't be time to process the image) or do a any kind of heavy logic in the render thread. The way your game would run, would initialize and load that image every tick the game makes, which would be roughly around whatever FPS you have and be way too heavy to process. – Samich Feb 13 '14 at 00:33

1 Answers1

1

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);

Samich
  • 579
  • 4
  • 13