I just started using the Slick2d game library (following this guide). For some reason the whole frame is black. I don't know what's wrong, because I'm getting complaints from neither Eclipse nor Slick2d.
Here is a screenshot of my project tree:
Here is the Game.java source:
package com.michael.ivorymoon;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class Game extends BasicGame
{
Image land = null;
Image plane = null;
float x = 400;
float y = 300;
float scale = 1.0f;
public Game()
{
super("Ivory Moon");
}
@Override
public void init(GameContainer container) throws SlickException
{
land = new Image("/res/land.jpg");
land.draw(0, 0);
plane = new Image("/res/plane.png");
plane.draw(x, y, scale);
}
@Override
public void update(GameContainer container, int delta) throws SlickException
{
;
}
@Override
public void render(GameContainer container, Graphics graphics) throws SlickException
{
;
}
public static void main(String[] args) throws SlickException
{
AppGameContainer appContainer = new AppGameContainer(new Game());
appContainer.setDisplayMode(800, 600, false);
appContainer.start();
}
}
You can find /res/land.jpg
over here. This is /res/plane.jpg
:
And finally, just in case you didn't believe me, here is the running application:
land = new Image("/res/land.jpg");
and
land = new Image("/res/plane.png");
are the culprit, the leading /
states you want to start at the base of your filesystem, an absolute path. Try using:
land = new Image("res/land.jpg");
land = new Image("res/plane.png");
This path is relative to your project, should work.
Also, draw calls need to be made within render method.