简体   繁体   English

Slick2d图像对象无法正确显示?

[英]Slick2d Image object not displaying correctly?

I just started using the Slick2d game library (following this guide). 我刚刚开始使用Slick2d游戏库(遵循指南)。 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. 我不知道出什么问题了,因为我既没有收到Eclipse也没有收到Slick2d的投诉。

Here is a screenshot of my project tree: 这是我的项目树的屏幕截图:

我的项目树

Here is the Game.java source: 这是Game.java的源代码:

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 . 您可以在此处找到/res/land.jpg This is /res/plane.jpg : 这是/res/plane.jpg

/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. 另外,绘制调用需要在render方法中进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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