Search code examples
javaslick2dtiled

How to load polygon objects from Tiled in Slick2d?


I need to load polygon objects drawn in Tiled into my slick2d game. I can load objects that are rectangles, and create collision boxes out of them, but I can't seem to find any way to load polygons?? (verticies and so on). Is this possible in slick2d?


Solution

  • Yo! So I managed to find a solution. I'll post what I did for anyone who is interested:

    What I did was I basicly took things in my own hands and added polygon support myself. I copied over all classes from org.newdawn.slick.tiled and made my own version of them, with polygon support added. In the TiledMap class, I modified the inner GroupObject class to include a Vec2 array called vertecies, I then modified the constructor so that it looked for a child called "Polygon" (which is where polygon information is stored) and then parsed the String value of the "points" attribute into an array of Vec2, which I stored in the vertices variable. I then added a getObjectVertices(int groupID, int objectID) method that returned the vertices variable.

    Hope this helps someone else out in my situation! Loading maps works beautifully now, and I'm quite proud of my little McGyver solution ;)