gpt4 book ai didi

java - Slick2D + Tiled 无法加载 map

转载 作者:行者123 更新时间:2023-12-01 04:36:08 24 4
gpt4 key购买 nike

我在任何地方都找不到这样的问题。

我有这样的结果:

Wed Jun 26 09:30:02 CEST 2013 INFO:Slick Build #237
Wed Jun 26 09:30:02 CEST 2013 INFO:LWJGL Version: 2.9.0
Wed Jun 26 09:30:02 CEST 2013 INFO:OriginalDisplayMode: 1366 x 768 x 32 @60Hz
Wed Jun 26 09:30:02 CEST 2013 INFO:TargetDisplayMode: 640 x 480 x 0 @0Hz
Wed Jun 26 09:30:02 CEST 2013 INFO:Starting display 640x480
Wed Jun 26 09:30:02 CEST 2013 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 7
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Wed Jun 26 09:30:02 CEST 2013 INFO:Found 0 controllers
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
at SlickTest.init(SlickTest.java:24)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at SlickTest.main(SlickTest.java:45)

对于这样的代码:

import java.util.logging.Level;
import java.util.logging.Logger;

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;
import org.newdawn.slick.tiled.TiledMap;

public class SlickTest extends BasicGame{
Image celownik;
private TiledMap grassMap = null;
public SlickTest(String title) {
super("Graaa");
// TODO Auto-generated constructor stub
}

@Override
public void init(GameContainer gc) throws SlickException {
//celownik = new Image("cross.png");

grassMap = new TiledMap("mapa.tmx"); // << this is the problem


}

@Override
public void update(GameContainer gc, int i) throws SlickException {
}

@Override
public void render(GameContainer gc, Graphics g) throws SlickException {
//grassMap.render(0, 0);
//g.drawString("r", 20,20);
//g.drawImage(celownik, 50,50);
}

public static void main(String[] args) {
try {
AppGameContainer appgc;
appgc = new AppGameContainer(new SlickTest("Simple Slick Game"));
appgc.setDisplayMode(640, 480, false);
appgc.start();
} catch (SlickException ex) {
Logger.getLogger(SlickTest.class.getName()).log(Level.SEVERE, null, ex);
}

}
}

我使用 Base64 gzip 压缩,所以一切都应该没问题。我找不到让我生病的因素;)。此异常是否可能是库放置不正确的结果?

最佳答案

好吧,如果您查看source TiledMap 类中,你会在构造函数中看到这样的代码:

ref = ref.replace('\\', '/');                
load(ResourceLoader.getResourceAsStream(ref),
ref.substring(0, ref.lastIndexOf("/")));

这意味着,您的 ref 参数应该是文件的路径,其中应该至少包含一个路径分隔符符号。如果没有它,ref.substring(0, ref.lastIndexOf("/")) 显然会抛出StringIndexOutOfBoundsException

关于java - Slick2D + Tiled 无法加载 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com