当前位置: 首页 > 知识库问答 >
问题:

能否在slick2d上更改平铺贴图?

轩辕实
2023-03-14

我用这个简单的if来改变

if(input.isKeyDown(Input.KEY_UP)) {
      sprite = up;
      if(!isBlocked(x,y - delta * 0.1f) && y > 0) {
         sprite.update(delta);                // lower delta = lower speed animation
          y -= delta * 0.1f;
      }
      if(isDoor(x,y - delta * 0.1f)) {
          currentMap = currentRoom.getNorth().getMap();
          currentRoom = currentRoom.getNorth();
      }
}

“currentMap”是当前正在渲染的平铺贴图。“currentRoom”是指当前房间中有瓷砖贴图的房间,因为我需要更多的东西来存储房间。问题是,当我走到门口时,游戏立即以空指针关闭,然而在崩溃之前,我可以看到地图发生了变化。

完整错误报告:

ERROR:null
java.lang.NullPointerException
at not.zuul.world.GameMain.update(GameMain.java:143)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)
Sat Oct 25 21:18:51 CEST 2014 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at not.zuul.world.GameMain.main(GameMain.java:40)

一些额外的代码,这些代码在init上调用。房间-字符串的哈希图,其中包含表示门的方向的字母(键),以及表示值的平铺贴图(由于门的组合不同,共有15个不同的房间)。

game\u map也是hashmap,其中字符串(name)表示键,class Room表示值。我用“setRooms”为那个房间设置“neighbor”,或者在那个些门通向的其他地方,顺序是(北、南、东、西)

public void initAllRooms() throws SlickException {
    rooms = new HashMap<String, TiledMap>();
    rooms.put("N", new TiledMap("resources/map/Rooms/room_north.tmx"));
    rooms.put("S", new TiledMap("resources/map/Rooms/room_south.tmx"));
    rooms.put("E", new TiledMap("resources/map/Rooms/room_east.tmx"));
    rooms.put("W", new TiledMap("resources/map/Rooms/room_west.tmx"));
    rooms.put("NE", new TiledMap("resources/map/Rooms/room_north_east.tmx"));
    rooms.put("NS", new TiledMap("resources/map/Rooms/room_north_south.tmx"));
    rooms.put("NW", new TiledMap("resources/map/Rooms/room_north_west.tmx"));
    rooms.put("SE", new TiledMap("resources/map/Rooms/room_south_east.tmx"));
    rooms.put("SW", new TiledMap("resources/map/Rooms/room_south_west.tmx"));
    rooms.put("EW", new TiledMap("resources/map/Rooms/room_east_west.tmx"));
    rooms.put("NSE", new TiledMap("resources/map/Rooms/room_north_south_east.tmx"));
    rooms.put("NSW", new TiledMap("resources/map/Rooms/room_north_south_west.tmx"));
    rooms.put("NEW", new TiledMap("resources/map/Rooms/room_north_east_west.tmx"));
    rooms.put("SEW", new TiledMap("resources/map/Rooms/room_south_east_west.tmx"));
    rooms.put("NSEW", new TiledMap("resources/map/Rooms/room_north_south_east_west.tmx"));
}

public void initMap() throws SlickException {
    game_map = new HashMap<String, Room>();
    game_map.put("outside", new Room(rooms.get("N"), "You're outside."));
    game_map.put("mainHall", new Room(rooms.get("NSEW"), "You're in main hall."));
    game_map.put("emptyRoom", new Room(rooms.get("NE"), "You're in empty room."));
    game_map.put("bathRoom", new Room(rooms.get("S"), "You're in bathroom"));
    game_map.put("kitchen", new Room(rooms.get("NW"), "You're in kitchen"));
    game_map.put("diningRoom", new Room(rooms.get("NS"), "You;re in dining room"));
    game_map.put("backYard", new Room(rooms.get("SE"), "You're in back yard"));
    game_map.put("storageRoom", new Room(rooms.get("W"), "You're in storage room"));

    game_map.get("outside").setRooms(game_map.get("mainHall"), null, null, null);
    game_map.get("mainHall").setRooms(game_map.get("diningRoom"), game_map.get("outside"),
            game_map.get("emptyRoom"), game_map.get("kitchen"));
    game_map.get("emptyRoom").setRooms(game_map.get("bathRoom"), null, game_map.get("mainHall"), null );
    game_map.get("bathRoom").setRooms(null, game_map.get("emptyRoom"), null, null);
    game_map.get("kitchen").setRooms(null, null, null, game_map.get("mainHall"));
    game_map.get("diningRoom").setRooms(game_map.get("backYard"), game_map.get("mainHall)"), null, null);
    game_map.get("backYard").setRooms(null, game_map.get("diningRoom"), game_map.get("storageRoom"), null);
    game_map.get("storageRoom").setRooms(null, null, null, game_map.get("backYard"));

}

共有1个答案

充阳秋
2023-03-14

除非您提供stacktrace和stacktrace来自的行,否则无法真正提供帮助。

编辑:仍然需要查看崩溃发生在哪一行。

 类似资料:
  • 我想让我的libgdx地图滚动,但我不知道代码使地图滚动,请大家帮助我,我想让地图滚动像flappy bird游戏,这是我的代码,显示在屏幕上的地图 }

  • 平铺贴图对象以像素表示x、y位置,以度表示旋转。 我正在从地图上加载坐标和旋转,并试图将它们指定给box2d实体。位置模型之间存在一些差异,例如平铺对象旋转以度为单位,而box2d躯干角度以弧度为单位。 如何将位置转换为BodyDef坐标x、y和角度,以便在正确的位置创建实体? 使用代码: 当旋转为0时工作,但当旋转不同于0时,主体定位不正确。 我在这里找到了一些提示: http://www.tu

  • 我知道有一个类似的问题,但答案不够具体,无法在我的案例中发挥作用。 我试图创建一个程序,可以显示在平铺中创建的平铺地图,并使用pytmx上传到Pygame中。我唯一的问题是在Pygame中将图像快速显示在屏幕上。 这就是我一直收到的错误:回溯(最近一次调用):文件“C:\Users\b\Desktop\Frozed Map Textures\test.py”,第32行,在screen.blit(i

  • 我的文件。 我有一个Struts2Action,它从数据库中获取数据并填充在在showdefinition中,我再次为另一个工作使用了另一个相同操作的方法,这次我填充了列表视图定义,但我以前的不保留其值。 我被困在这一个星期了,请帮帮我。

  • 我正在编程一个小游戏,它是基于瓷砖的。但当我渲染它的时候,有时那些瓷砖之间的一个小空间是可见的,(绿色)背景是暴露的(可以在视频中看到)。 我想知道,是否有一些双缓冲技术,可以解决这个bug,但我读到,双缓冲已经实现了。

  • 将数组平铺到指定的深度。 使用递归,为每个深度级别 depth 递减 1 。 使用 Array.reduce() 和 Array.concat() 来合并元素或数组。 基本情况下,depth 等于 1 停止递归。 省略第二个参数,depth 只能平铺到 1 (单层平铺) 的深度。 const flatten = (arr, depth = 1) => depth != 1 ? arr.