我有个问题,我是个新手,我正在做一个侧面监控器。我正在尝试在stateBasedGame中加载spritesheet。但当我运行/调试游戏时,它会运行,但不会显示图像。代码如下:
//private static Map<String, Image> images;
private static Map<String, SpriteSheet> sprites;
//private static Map<String, Sound> sounds;
public Resources() {
//images = new HashMap<String, Image>();
sprites = new HashMap<String, SpriteSheet>();
//sounds = new HashMap<String, Sound>();
try {
sprites.put("tiles", loadSprite("resources/tiles.png", 32, 32));
} catch (SlickException e) {
e.printStackTrace();
}
}
private Image loadImage(String path) throws SlickException {
return new Image(path, false, Image.FILTER_NEAREST);
}
private SpriteSheet loadSprite(String path, int tw, int th) throws SlickException {
return new SpriteSheet(loadImage(path), tw, th);
}
public static Image getSpriteImage(String getter, int x, int y) {
sprites.get(getter).getSubImage(x, y);
return null;
}在GameState中我放了这个:
Resources.getSpriteImage("tiles", 0, 0);我仔细检查了路径,这是正确的。请帮帮我!
发布于 2014-10-19 01:59:27
这是正确的,问题是你没有调用draw方法,你只得到了图像的一个实例。
试试这个: Resources.getSpriteImage("tiles",0,0).draw(0,0);
发布于 2015-03-02 02:14:11
您的方法getSpriteImage需要返回图像,而不是返回null:
public static Image getSpriteImage(String getter, int x, int y) {
return sprites.get(getter).getSubImage(x, y);
}别忘了在你的GameState中实际绘制磁贴:
Resources.getSpriteImage("tiles", 0, 0).draw(0, 0);https://stackoverflow.com/questions/26431569
复制相似问题