我最近一直在用java编写平台游戏,当我尝试使用单独的类来存储我的地图(平铺)时遇到了问题。然后我尝试通过将地图移动到主类来修复它,但它没有帮助。
这是导致问题的代码(当world.map1.render(0,0)被删除时,不存在问题) - 我知道我应该使用 getter 和 setter。我只是觉得他们很痛苦。
public void render(GameContainer arg0, Graphics arg1) throws SlickException {
world.map1.render(0, 0);
}
这是主要方法
public static void main(String[] args) throws SlickException{
AppGameContainer app = new AppGameContainer(new Game());
app.setDisplayMode(864, 480, false);
app.setVSync(true);
app.start();
playerSheet = new SpriteSheet("resources/images/link3goldstudmod.png", 64, 64);
player = new Player(playerSheet);
world = new World();
}
这是世界级的
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
public class World {
TiledMap map1;
World() throws SlickException{
map1 = new TiledMap("resources/maps/map1.tmx");
}
}
编辑:我忘了发布问题/堆栈废话/无论如何。我真傻。
Mon Feb 18 16:33:58 MST 2013 INFO:Slick Build #264
Mon Feb 18 16:33:58 MST 2013 INFO:LWJGL Version: 2.8.5
Mon Feb 18 16:33:58 MST 2013 INFO:OriginalDisplayMode: 1920 x 1080 x 32 @60Hz
Mon Feb 18 16:33:58 MST 2013 INFO:TargetDisplayMode: 864 x 480 x 0 @0Hz
Mon Feb 18 16:33:58 MST 2013 INFO:Starting display 864x480
Mon Feb 18 16:33:58 MST 2013 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 8
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Mon Feb 18 16:33:59 MST 2013 INFO:Found 3 controllers
Mon Feb 18 16:33:59 MST 2013 INFO:0 : USB Receiver
Mon Feb 18 16:33:59 MST 2013 INFO:1 : USB Receiver
Mon Feb 18 16:33:59 MST 2013 INFO:2 : Logitech Speaker
Mon Feb 18 16:33:59 MST 2013 ERROR:null
java.lang.NullPointerException
at zeldaplatform.Game.render(Game.java:36)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:703)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at zeldaplatform.Game.main(Game.java:27)
Mon Feb 18 16:33:59 MST 2013 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:706)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at zeldaplatform.Game.main(Game.java:27)
这不是什么大错误,因为它编译得很好,然后控制台给了我这个。窗口出现片刻,然后消失。