xaguzman / pathfinding

Java pathfinding framework.
Apache License 2.0
96 stars 28 forks source link

TiledMapTileLayer cannot be cast to NavigationTiledMapLayer #7

Closed thomaslecoeur closed 9 years ago

thomaslecoeur commented 9 years ago

Hello, and thank you for your project !

I have an issue using your astar algorithm with my TiledMap. I basically used the code you give in your exemple :

TiledMap map = new NavTmxMapLoader().load(level.file);

AStarGridFinder<GridCell> finder = new AStarGridFinder<GridCell>(GridCell.class);

NavigationTiledMapLayer nav = (NavigationTiledMapLayer)map.getLayers().get("meta");

List<GridCell> path = finder.findPath(this.getPosX(), this.getPosY(), player.getPosX(), player.getPosY(), nav);

for(GridCell c : path){
    Gdx.app.log("Map Loading Test - path: ", c.toString());
}

Wich give me this error :

Exception in thread "LWJGL Application" java.lang.ClassCastException: com.badlogic.gdx.maps.tiled.TiledMapTileLayer cannot be cast to org.xguzm.pathfinding.gdxbridge.NavigationTiledMapLayer

Do you have any clue ?

Thank you for your help ! Thomeuxe

xaguzman commented 9 years ago

Could you provide the map which is giving you trouble?

thomaslecoeur commented 9 years ago

Here is the xml of my .tmx map :

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="35" height="10" tilewidth="32" tileheight="32" nextobjectid="11">
 <tileset firstgid="1" name="sol" tilewidth="32" tileheight="32">
  <image source="floor.png" width="32" height="32"/>
 </tileset>
 <tileset firstgid="2" name="wall" tilewidth="32" tileheight="32">
  <image source="wall.png" width="32" height="32"/>
  <tile id="0">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
 </tileset>
 <tileset firstgid="3" name="Wall" tilewidth="32" tileheight="32">
  <image source="wall_new.png" width="128" height="96"/>
  <tile id="0">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="1">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="2">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="3">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="4">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="5">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="6">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="7">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="8">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="9">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="10">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
  <tile id="11">
   <properties>
    <property name="collidable" value="true"/>
   </properties>
  </tile>
 </tileset>
 <tileset firstgid="15" name="meta" tilewidth="32" tileheight="32">
  <image source="meta.png" width="96" height="32"/>
  <tile id="0">
   <properties>
    <property name="start" value="true"/>
   </properties>
  </tile>
  <tile id="1">
   <properties>
    <property name="spawn_enemy" value="true"/>
   </properties>
  </tile>
  <tile id="2">
   <properties>
    <property name="exit" value="true"/>
   </properties>
  </tile>
 </tileset>
 <layer name="background" width="35" height="10">
  <data encoding="base64" compression="zlib">
   eJxjZGBgYBzFo3gUj+JRTDcMAMVpAV8=
  </data>
 </layer>
 <layer name="collision" width="35" height="10">
  <data encoding="base64" compression="zlib">
   eJzjYWBg4BkEmB2IOYGYcRBgfG5hBmIWLJh1ANwCkuPAgpHV89HQLXwMpLkFXxiSGn74woWbAXsa4yUyDElNh9RKuwPpFvR0gi0MsYUfPcKFmmkXW94dCAwA9TAFTA==
  </data>
 </layer>
 <layer name="meta" width="35" height="10">
  <data encoding="base64" compression="zlib">
   eJxjYBgFhAA/DcwUQMIMaGx6A1xuGQg34bObWm4h1hx0twxkXOEKl4FIM4TShyAU0xMMJrcQAwA97gKU
  </data>
 </layer>
</map>
xaguzman commented 9 years ago

Try renaming your layer to "navigation",or If you want to keep your name (meta) you need to use a different constructor for the navtmxmaploader. El abr 8, 2015 2:34 PM, "Thomeuxe" notifications@github.com escribió:

Here is the xml of my .tmx map :

<?xml version="1.0" encoding="UTF-8"?>

eJxjZGBgYBzFo3gUj+JRTDcMAMVpAV8= eJzjYWBg4BkEmB2IOYGYcRBgfG5hBmIWLJh1ANwCkuPAgpHV89HQLXwMpLkFXxiSGn74woWbAXsa4yUyDElNh9RKuwPpFvR0gi0MsYUfPcKFmmkXW94dCAwA9TAFTA== eJxjYBgFhAA/DcwUQMIMaGx6A1xuGQg34bObWm4h1hx0twxkXOEKl4FIM4TShyAU0xMMJrcQAwA97gKU

— Reply to this email directly or view it on GitHub https://github.com/xaguzman/pathfinding/issues/7#issuecomment-91013384.

thomaslecoeur commented 9 years ago

After doing this I got this error :

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: com/badlogic/gdx/maps/tiled/TmxMapHelper
xaguzman commented 9 years ago

Hmmm what libgdx version are you using? El abr 8, 2015 3:14 PM, "Thomeuxe" notifications@github.com escribió:

After doing this I got this error :

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: com/badlogic/gdx/maps/tiled/TmxMapHelper

— Reply to this email directly or view it on GitHub https://github.com/xaguzman/pathfinding/issues/7#issuecomment-91022991.

thomaslecoeur commented 9 years ago

I'm using LibGDX 1.5.3. It's not compatible with it ? Can I still use your project without using tmx ?

xaguzman commented 9 years ago

I wrote the library against v 1.5.2. It seems that by version 1.5.3 they removed that class (TmxMapHelper).

Will fix asap. I will open a new issue regarding this

xaguzman commented 9 years ago

And yes, you can still use this pathfinding library without the bridge. You would just need to provide the GridCell[][] matrix yourself.

xaguzman commented 9 years ago

Issue #8 has been resolved, please update to version 0.2.5 to get the gdx-bridge working again! Thanks for spotting the issue!