JSTileMap How to Convert polygon points

99 views Asked by At

I am trying to turn a polygon object in my tiled map into a physics body.

I can't figure out how to read the following line and turn it into 3 CGPoint values:

<polygon points="109,6 395,71 -142,69"/>

I am using JSTileMap to parse the TMX map but can't find anything in the documentation to do this.

Any help appreciated!

1

There are 1 answers

0
Thorbjørn Lindeijer On BEST ANSWER

It seems that JSTileMap simply uses an NSDictionary to represent objects, and one of the entries in this dictionary is "polygonPoints", which is the same string as you find on that points attribute. You can see this by looking at the source code here.

So that should give you an idea about how to get at the string value, but you'll still need to split it on the space character to get the "x,y" parts and then split it again on the comma and convert the individual values to numbers.

You'll finally probably want to do some coordinate conversion since those values are in pixels while physics bodies are more commonly defined in meters.