简体   繁体   中英

Slick2d background

I am trying to render a background image in my Slick2d window. However, it's not rendering. What's wrong?

This is the first part of my main class

public class SimpleGame extends BasicGame{

Image land = null;

public SimpleGame()
{
    super("Slick2DPath2Glory - SimpleGame");
}

@Override
public void init(GameContainer gc) throws SlickException {
    land = new Image("bg.jpg");
    land.draw(0,0);
}

Here's the root tree http://billedeupload.dk/images/4J5CQ.png

You should do all the rendering in the render() method instead of the init() method. So something like this:

@Override
public void init(GameContainer gc) throws SlickException {
    land = new Image("bg.jpg");        
}

@Override
public void render(GameContainer gc, StateBasedGame sb, Graphics g) throws SlickException {
    g.drawImage(land, 0, 0);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM