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?
1 Answers
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 ;)

- 53
- 7
-
That's great! Did you consider contributing back your improvements to Slick2D at https://bitbucket.org/kevglass/slick? – Thorbjørn Lindeijer Nov 16 '15 at 09:00
-
I'm not familiar with bitBucket, but if I could get an overview of how it works I'm sure I could polish my code a bit and send it in :) You would have to look over it though, don't want to contribute buggy code. I didn't know Slick2d is still being worked on.. Where can I find the newest version? – Tholok Nov 19 '15 at 17:43
-
1Commits are certainly very rare, but there was still some activity this year. I found the link to the repository at http://slick.ninjacave.com/wiki/index.php?title=Main_Page so I think this should be the latest version. You can read more about using Bitbucket at https://bitbucket.org/support. Note that I'm the developer of Tiled, not Slick2D, but if you open a pull request feel free to link me to it as well. – Thorbjørn Lindeijer Nov 20 '15 at 19:35