开发者

Slick: can't load image in update loop

As you can see from the code below, I am trying to import "someimage.png". This is so in the开发者_JS百科 render loop, I have the right image. I put the second line of code. Is this possible? If not what is an alternative. Thanks in advance.

public void update(GameContainer container, int delta) {
    //if statement
    Image x = new Image("someimage.png");
}
public void render() {
    //draw image x
}

There is an "unhanded exception type SlickException".


It looks like the variable "x" is local to the update() function. If your render() function tries to call "x", maybe it's a different variable?


Check out this Slick tutorial here, it shows a basic game setup with image loading. Basically, you want the Images to be member variables of your game class, their values set in the init method, and the render method to draw the pictures. Although this setup will work fine for very simple games, you are probably better off using objects to represent the different things in your game. I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜