mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1930 from NatWeiss/tmxpolygons
Added TMX polygon parsing.
This commit is contained in:
commit
7f594f00b8
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
#include "CCTMXXMLParser.h"
|
#include "CCTMXXMLParser.h"
|
||||||
#include "CCTMXTiledMap.h"
|
#include "CCTMXTiledMap.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
@ -599,10 +600,55 @@ void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
else if (elementName == "polygon")
|
else if (elementName == "polygon")
|
||||||
{
|
{
|
||||||
// find parent object's dict and add polygon-points to it
|
// find parent object's dict and add polygon-points to it
|
||||||
// CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
|
||||||
// CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
|
CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
|
||||||
// TODO: dict->setObject(attributeDict objectForKey:@"points"] forKey:@"polygonPoints"];
|
|
||||||
|
|
||||||
|
// get points value string
|
||||||
|
const char* value = valueForKey("points", attributeDict);
|
||||||
|
if(value)
|
||||||
|
{
|
||||||
|
CCArray* pPointsArray = new CCArray;
|
||||||
|
|
||||||
|
// parse points string into a space-separated set of points
|
||||||
|
stringstream pointsStream(value);
|
||||||
|
string pointPair;
|
||||||
|
while(std::getline(pointsStream, pointPair, ' '))
|
||||||
|
{
|
||||||
|
// parse each point combo into a comma-separated x,y point
|
||||||
|
stringstream pointStream(pointPair);
|
||||||
|
string xStr,yStr;
|
||||||
|
char buffer[32] = {0};
|
||||||
|
|
||||||
|
CCDictionary* pPointDict = new CCDictionary;
|
||||||
|
|
||||||
|
// set x
|
||||||
|
if(std::getline(pointStream, xStr, ','))
|
||||||
|
{
|
||||||
|
int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
|
||||||
|
sprintf(buffer, "%d", x);
|
||||||
|
CCString* pStr = new CCString(buffer);
|
||||||
|
pStr->autorelease();
|
||||||
|
pPointDict->setObject(pStr, "x");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set y
|
||||||
|
if(std::getline(pointStream, yStr, ','))
|
||||||
|
{
|
||||||
|
int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
|
||||||
|
sprintf(buffer, "%d", y);
|
||||||
|
CCString* pStr = new CCString(buffer);
|
||||||
|
pStr->autorelease();
|
||||||
|
pPointDict->setObject(pStr, "y");
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to points array
|
||||||
|
pPointsArray->addObject(pPointDict);
|
||||||
|
pPointDict->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
dict->setObject(pPointsArray, "points");
|
||||||
|
pPointsArray->release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (elementName == "polyline")
|
else if (elementName == "polyline")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue