you can use the following code piece to retrieve the polygon points:
CCDictionary* dict = (CCDictionary**)objectGroup~~>getObjects~~>lastObject;
CCArray* points = dict~~>objectForKey;
for ; ++i) {
CCDictionary* dict2 = points~~>objectAtIndex;
const char** key = “x”;
int x = ((CCString**)dict2~~>objectForKey)>intValue;
key = “y”;
int y = dict2>objectForKey)>intValue;
CCLOG (“x=%d, y=%d”,x,y);
}
Warning:
It seems you can’t retrieve polyline points with the newest version of cocos2d-x, you can refer to CCTMXXMLParse.cpp , line 623 for more infomation.
the parse codes of polyline are missing, if you want wo retrieve the polyline points, you can refer to this thread:
http://www.cocos2d-x.org/boards/6/topics/12122
I don’t test the above code either, so be careful and wish you good luck.
Update:
In the above code, you’d better add name property to each polygon and polyline object, so you can use objectGroup>objectName to retrieve the desired object.
then you can use the following code to retrieve polyline & polygon:
CCTMXObjectGroup objectGroup = tiledMap~~>objectGroupNamed;
CCDictionary* dict = objectGroup~~>objectNamed;
CCArray points = dict~~>objectForKey;
for ; ++i) {
CCDictionary** dict2 = (CCDictionary*)points~~>objectAtIndex;
const char* key = “x”;
int x = dict2~~>objectForKey(“x”))>intValue;
key = “y”;
int y = dict2>objectForKey(key))>intValue;
CCLOG (“x=%d, y=%d”,x,y);
}
CCDictionary **polyline = objectGroup>objectNamed;
CCLOG (“polyline=%s”, ((CCString*)polyline~~>objectForKey)>getCString);
CCArray *array = objectGroup>getObjects;
CCObject** pObj = NULL;
CCARRAY_FOREACH
{
dict = pObj;
if
{
break;
}
const char* key = “x”;
int x = dict~~>objectForKey(key))>intValue;
key = “y”;
int y = dict>objectForKey(key))>intValue;
key = “width”;
int width = dict>objectForKey(key))>intValue;
key = “height”;
int height = dict>objectForKey(key))~~>intValue;
CCLOG (“x=%d, y= %d, width=%d, height=%d”,x,y,width,height);
}
This is my tmx file:
<pre>
<?xml version="1.0" encoding="UTF-8"?>
<map version=“1.0” orientation=“orthogonal” width=“20” height=“10” tilewidth=“32” tileheight=“32”>
H4sIAAAAAAAAA2NlYGBgA2J2IOYAYk40zAXE3EDMA8S8WORJVc8PxAJALAjEQkSYR6r6kYjFsLDF8KjFJidOQC2MFsGBhaEYWUwUB8ZlBjLmg2Ji1NLSPACAEDAIIAMAAA==
H4sIAAAAAAAAA2NgGBmAhQJ9MExts5H14jKDkN3UBsT4dyQBAIF16DMgAwAA
<object name=“StartPoint” x=“14” y=“151” width=“18” height=“18”/>
<object name=“first” x=“213” y=“47”>
</object>
<object name=“second” x=“418” y=“52”>
</object>
</map>
</pre>
and my output:
<pre>
Cocos2d: x=0, y=0
Cocos2d: x=96, y=96
Cocos2d: x=137, y=5
Cocos2d: polyline=0,0 79,~~4
Cocos2d: x=14, y= 151, width=18, height=18
Cocos2d: x=213, y= 273, width=0, height=0
Cocos2d: x=418, y= 268, width=0, height=0
if you want to retrieve x,y property from polyline, you can refer to CCTMXXMLParse.cpp , line 623 for more infomation.