本文整理汇总了C++中CCDictionary::count方法的典型用法代码示例。如果您正苦于以下问题:C++ CCDictionary::count方法的具体用法?C++ CCDictionary::count怎么用?C++ CCDictionary::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCDictionary
的用法示例。
在下文中一共展示了CCDictionary::count方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isSame
bool AmfUtil::isSame(cocos2d::CCObject *thisObj, cocos2d::CCObject *thatObj) {
if (thisObj && !thatObj) return false;
if (!thisObj && thatObj) return false;
if (!thisObj && !thatObj) return true;
if (dynamic_cast<CCBool *>(thisObj) && dynamic_cast<CCBool *>(thatObj)) {
return dynamic_cast<CCBool *>(thisObj)->getValue() == dynamic_cast<CCBool *>(thatObj)->getValue();
} else if (dynamic_cast<CCInteger *>(thisObj) && dynamic_cast<CCInteger *>(thatObj)) {
return dynamic_cast<CCInteger *>(thisObj)->getValue() == dynamic_cast<CCInteger *>(thatObj)->getValue();
} else if (dynamic_cast<CCFloat *>(thisObj) && dynamic_cast<CCFloat *>(thatObj)) {
return dynamic_cast<CCFloat *>(thisObj)->getValue() == dynamic_cast<CCFloat *>(thatObj)->getValue();
} else if (dynamic_cast<CCDouble *>(thisObj) && dynamic_cast<CCDouble *>(thatObj)) {
return dynamic_cast<CCDouble *>(thisObj)->getValue() == dynamic_cast<CCDouble *>(thatObj)->getValue();
} else if (dynamic_cast<CCString *>(thisObj) && dynamic_cast<CCString *>(thatObj)) {
return strcmp(dynamic_cast<CCString *>(thisObj)->getCString(), dynamic_cast<CCString *>(thatObj)->getCString()) == 0;
} else if (dynamic_cast<CCDate *>(thisObj) && dynamic_cast<CCDate *>(thatObj)) {
return dynamic_cast<CCDate *>(thisObj)->isEqual(dynamic_cast<CCDate *>(thatObj));
} else if (dynamic_cast<AmfTraitsInfo *>(thisObj) && dynamic_cast<AmfTraitsInfo *>(thatObj)) {
return dynamic_cast<AmfTraitsInfo *>(thisObj)->isEqual(dynamic_cast<AmfTraitsInfo *>(thatObj));
} else if (dynamic_cast<AmfObject *>(thisObj) && dynamic_cast<AmfObject *>(thatObj)) {
return dynamic_cast<AmfObject *>(thisObj)->isEqual(dynamic_cast<AmfObject *>(thatObj));
} else if (dynamic_cast<AmfCoding *>(thisObj) && dynamic_cast<AmfCoding *>(thatObj)) {
return dynamic_cast<AmfCoding *>(thisObj)->isEquals(thatObj);
} else if (dynamic_cast<CCArray *>(thisObj) && dynamic_cast<CCArray *>(thatObj)) {
CCArray *thisArray = dynamic_cast<CCArray *>(thisObj);
CCArray *thatArray = dynamic_cast<CCArray *>(thatObj);
int count = thisArray->count();
int capacity = thisArray->capacity();
if (count != thatArray->count() || (count == 0 && capacity != thatArray->capacity()))
return false;
for (int i = 0; i < count; i++) {
if (!isSame(thisArray->objectAtIndex(i), thatArray->objectAtIndex(i)))
return false;
}
return true;
} else if (dynamic_cast<CCDictionary *>(thisObj) && dynamic_cast<CCDictionary *>(thatObj)) {
CCDictionary *thisDict = dynamic_cast<CCDictionary *>(thisObj);
CCDictionary *thatDict = dynamic_cast<CCDictionary *>(thatObj);
int count = thisDict->count();
if (count != thatDict->count())
return false;
CCDictElement *thisElement;
CCDICT_FOREACH(thisDict, thisElement) {
char const *thisKey = thisElement->getStrKey();
CCObject *thatValue = thatDict->objectForKey(thisKey);
if (!thatValue) return false;
if (!isSame(thisElement->getObject(), thatValue)) return false;
}
示例2: Init
void LevelMgr::Init(CCLayer* layer)
{
mGameLayer = layer;
//¶ÁfishInfo
const char* testPlistPath = "fish/GamePart.plist";
std::string str1 = CCFileUtils::sharedFileUtils()->fullPathForFilename(testPlistPath);
CCDictionary* plistDic = CCDictionary::createWithContentsOfFile(str1.c_str());
mLevelCount = plistDic->count();
char str[64] = {0};
for(int i=1;i<=mLevelCount;i++)
{
sprintf(str,"level%d",i);
CCDictionary* levelDic = dynamic_cast<CCDictionary*>(plistDic->objectForKey(str));
LevelInfo levelInfo;
strcpy(levelInfo.fishList,levelDic->valueForKey("fish")->getCString());
strcpy(levelInfo.fishCount,levelDic->valueForKey("fishCount")->getCString());
levelInfo.time = levelDic->valueForKey("time")->intValue();
strcpy(levelInfo.music,levelDic->valueForKey("bgMusic")->getCString());
CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(levelInfo.music);
strcpy(levelInfo.background,levelDic->valueForKey("background")->getCString());
mLevelInfoList.push_back(levelInfo);
}
mMainFrame = UIMgr::Instance()->GetMainFrame();
// Ô¤¼ÓÔØÒôÀÖºÍÒôЧ
}
示例3:
CCArray * GAFAsset::objectStatesFromConfigFrame(CCDictionary * configFrame)
{
if (!configFrame)
{
return NULL;
}
CCDictionary * stateNodes = (CCDictionary *) configFrame->objectForKey(kFrameStateKey);
if (!stateNodes)
{
return NULL;
}
CCArray *states = CCArray::createWithCapacity(stateNodes->count());
CCDictElement* pElement = NULL;
CCDICT_FOREACH(stateNodes, pElement)
{
CCDictionary * stateDictionary = (CCDictionary *)pElement->getObject();
GAFSubobjectState * state = GAFSubobjectState::createWithStateDictionary(stateDictionary, pElement->getStrKey());
if (state)
{
states->addObject(state);
}
else
{
CCLOGINFO("GAFSubobjectState cannot be created. Ignoring.");
}
}
示例4: CCAssert
void GB2ShapeCache::addShapesWithFile(const std::string &plist) {
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(plist.c_str());
//dictionaryWithContentsOfFileThreadSafe(plist.c_str());
CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found
CCAssert(dict->count() != 0, "plist file empty or not existing");
CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata");
int format = static_cast<CCString *>(metadataDict->objectForKey("format"))->intValue();
ptmRatio = static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->floatValue();
CCAssert(format == 1, "Format not supported");
CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies");
b2Vec2 vertices[b2_maxPolygonVertices];
CCDictElement* pElement = NULL;
CCDICT_FOREACH(bodyDict, pElement)
{
BodyDef *bodyDef = new BodyDef();
CCString *bodyName = ccs(pElement->getStrKey());
CCDictionary *bodyData = (CCDictionary *)pElement->getObject();
bodyDef->anchorPoint = CCPointFromString(static_cast<CCString *>(bodyData->objectForKey("anchorpoint"))->getCString());
CCArray *fixtureList = (CCArray *)bodyData->objectForKey("fixtures");
FixtureDef **nextFixtureDef = &(bodyDef->fixtures);
CCObject *fixture = NULL;
CCARRAY_FOREACH(fixtureList, fixture)
{
b2FixtureDef basicData;
CCDictionary *fixtureData = (CCDictionary *)fixture;
int callbackData = 0;
basicData.filter.categoryBits = static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->intValue();
basicData.filter.maskBits = static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->intValue();
basicData.filter.groupIndex = static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->intValue();
basicData.friction = static_cast<CCString *>(fixtureData->objectForKey("friction"))->floatValue();
basicData.density = static_cast<CCString *>(fixtureData->objectForKey("density"))->floatValue();
basicData.restitution = static_cast<CCString *>(fixtureData->objectForKey("restitution"))->floatValue();
basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->intValue();
if(fixtureData->objectForKey("id")){
basicData.userData = static_cast<CCString *>(fixtureData->objectForKey("id"));
callbackData = static_cast<CCString *>(fixtureData->objectForKey("id"))->intValue();
}
std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString();
//CCString *fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString();
if (fixtureType == "POLYGON") {
//CCDictionary *polygons = (CCDictionary *)fixtureData->objectForKey("polygons");
CCArray *polygons = (CCArray *)fixtureData->objectForKey("polygons");
//CCDictElement *polygon = NULL;
CCObject *polygon = NULL;
//CCDICT_FOREACH(polygons, polygon)
CCARRAY_FOREACH(polygons, polygon)
{
FixtureDef *fix = new FixtureDef();
fix->fixture = basicData; // copy basic data
fix->callbackData = callbackData;
b2PolygonShape *polyshape = new b2PolygonShape();
int vindex = 0;
//CCDictionary *polygonData = (CCDictionary *)polygon->getObject();
CCArray *polygonData = (CCArray *)polygon;
assert(polygonData->count() <= b2_maxPolygonVertices);
//CCDictElement *offset = NULL;
CCObject *offset = NULL;
//CCDICT_FOREACH(polygonData, offset)
CCARRAY_FOREACH(polygonData, offset)
{
CCString *pStr = (CCString *)offset;
CCPoint p = CCPointFromString(pStr->getCString());
vertices[vindex].x = (p.x / ptmRatio) ;
vertices[vindex].y = (p.y / ptmRatio) ;
vindex++;
}
示例5: useItem
void RequestList::useItem(CCObject* pSender)
{
if (pSender == NULL)
{
return;
}
CCMenuItemImage* sender = (CCMenuItemImage*)pSender;
CCLOG("Call for useItem for tag = %d", sender->getTag());
if (sender->getTag() > _fbIncomingRequestList->count())
{
return;
}
std::string messageToDisplay = "";
EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(sender->getTag());
if (fbRequest->isConsumed())
{
CCMessageBox("This item is already consumed.", "Consume Item Status");
return;
}
EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
const char* senderName = fbRequest->getSender()->getName();
const char* requestTypeChar = "";
const char* message = "";
message = fbRequest->getMessage();
CCDictionary* giftDictionary = fbRequest->getDataDictionary();
switch (requestType)
{
case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
requestTypeChar = "Invite";
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
requestTypeChar = "Gift";
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
requestTypeChar = "Challenge";
break;
default:
requestTypeChar = "Unknown";
break;
}
// Add the request Type
messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n");
// Add the sender Name
messageToDisplay.append("Sender = ").append(senderName).append("\n");
// Add the message.
messageToDisplay.append("Message = ").append(message).append("\n");
if (giftDictionary && giftDictionary->count()>0)
{
CCArray* allKeys = giftDictionary->allKeys();
if (allKeys && allKeys->count() > 0)
{
messageToDisplay.append("Extra/Gift items sent:\n");
for (int i=0; i<allKeys->count(); i++)
{
CCString* key = (CCString*)allKeys->objectAtIndex(i);
CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString());
messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n");
}
}
}
else
{
messageToDisplay.append("No Extra Items were sent by sender");
}
CCMessageBox(messageToDisplay.c_str(), "Item Consumed!!! :)))");
EziFBIncomingRequestManager::sharedManager()->consumeItem(fbRequest);
CCScene *pScene = CCScene::create();
RequestList *pLayer = RequestList::create();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
}
示例6: tableCellTouched
void RequestList::tableCellTouched(CCTableView *table, CCTableViewCell *cell)
{
CCLOG("cell touched at index: %i", cell->getIdx());
std::string messageToDisplay = "";
EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(cell->getIdx());
EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
const char* senderName = fbRequest->getSender()->getName();
const char* requestTypeChar = "";
const char* message = "";
message = fbRequest->getMessage();
CCDictionary* giftDictionary = fbRequest->getDataDictionary();
switch (requestType)
{
case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
requestTypeChar = "Invite";
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
requestTypeChar = "Gift";
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
requestTypeChar = "Challenge";
break;
default:
requestTypeChar = "Unknown";
break;
}
// Add the request Type
messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n");
// Add the sender Name
messageToDisplay.append("Sender = ").append(senderName).append("\n");
// Add the message.
messageToDisplay.append("Message = ").append(message).append("\n");
if (giftDictionary && giftDictionary->count()>0)
{
CCArray* allKeys = giftDictionary->allKeys();
if (allKeys && allKeys->count() > 0)
{
messageToDisplay.append("Extra/Gift items sent:\n");
for (int i=0; i<allKeys->count(); i++)
{
CCString* key = (CCString*)allKeys->objectAtIndex(i);
CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString());
messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n");
}
}
}
else
{
messageToDisplay.append("No Extra Items were sent by sender");
}
CCMessageBox(messageToDisplay.c_str(), "Request Details");
}
示例7: getEnemiesListFromLayer
CCArray* LoadLevelEnemies::getEnemiesListFromLayer(CCTMXTiledMap *tilemap,
Player *player) {
CCTMXLayer* layer = tilemap->layerNamed("enemies");
CCSize layersize = layer->getLayerSize();
CCLOG("%s \n", "setEnemiesTilesInformation");
CCArray *enemieArray = CCArray::create();
CCDictionary* enemiesDictionary = PersistenceAux::getEnemyData();
CCLOG("Enemy data loaded");
for (int x = 0; x < layersize.width; x++) {
for (int y = 0; y < layersize.height; y++) {
unsigned int tmpgid = layer->tileGIDAt(ccp(x, y));
if (tmpgid != 0) {
CCSprite* tile = layer->tileAt(ccp(x, y));
CCRect box = tile->boundingBox();
CCPoint boxsize = ccp(box.size.width, box.size.height);
CCPoint tilePosition = ccpAdd(tile->getPosition(),
ccpMult(boxsize, 0.5));
layer->removeTileAt(ccp(x, y));
// create the enemy directly
CCDictionary* tileProperties = tilemap->propertiesForGID(
tmpgid);
CCLOG("%s \n", "dictionary for enemies properties");
CCString* enemyName = (CCString*) tileProperties->objectForKey(
"name");
CCLOG("Enemy name %s \n", enemyName->getCString());
CCDictionary* enemyProperties =
(CCDictionary *) enemiesDictionary->objectForKey(
enemyName->getCString());
CCLOG("Enemy prop. Dictionary size %d \n",
enemyProperties->count());
CCLOG("Enemy Position x %d \n", tilePosition.x);
CCLOG("************** PLIST ****************** \n");
CCLOG("SPEED %s",
((CCString*) enemyProperties->objectForKey("speed"))->getCString());
CCLOG("JUMPFORCE %s",
((CCString*) enemyProperties->objectForKey("jump"))->getCString());
CCLOG("SIGHT %s",
((CCString*) enemyProperties->objectForKey("sight"))->getCString());
CCLOG("DIFICULT %s",
((CCString*) enemyProperties->objectForKey("dificult"))->getCString());
CCLOG("DEFAULT IMAGE %s",
((CCString*) enemyProperties->objectForKey(
"defaultimage"))->getCString());
CCLOG("************** PLIST END ****************** \n");
MeeleEnemy* enemy = MeeleEnemy::create(
(CCString*) enemyProperties->objectForKey(
"defaultimage"),
(CCString*) enemyProperties->objectForKey("dificult"),
(CCString*) enemyProperties->objectForKey("jump"),
(CCString*) enemyProperties->objectForKey("sight"),
(CCString*) enemyProperties->objectForKey("speed"),
tilePosition, enemyName,
(CCString*) enemyProperties->objectForKey("damage")
);
CCLOG("%s \n", "Initializing enemies");
enemy->initMeeleEnemy(player);
CCLOG("%s \n", "Add enemies to enemy array");
enemieArray->addObject(enemy);
}
}
}
return enemieArray;
}
示例8: getConfigOfMapLevel
MapItem* CData::getConfigOfMapLevel(int levelid)
{
if(m_config_map_level_dic->count()<1)
{
Json::Reader read;
Json::Value root;
Json::Value data;
Json::Value list;
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("map.json");
CCString* str = CCString::createWithContentsOfFile(path.c_str());
int sz = 0;
if(read.parse(str->getCString(), root)){
data = root["data"];
sz = data.size();
for (int i = 0; i < sz; i++) {
MapItem *item = new MapItem();
// item->autorelease();
item->nickname = data[i]["name"].asString();
item->desc = data[i]["desc"].asString();
item->bid = data[i]["id"].asInt();
item->exp = data[i]["exp"].asInt();
item->coin = data[i]["coin"].asInt();
// item->itemId = root[i]["dropicon"].asInt();
list = data[i]["mconfig"];
CCDictionary* dic = CCDictionary::create();
int len =list.size();
for (int ei = 0; ei < len; ei++)
{
int iiiiid = list[ei].asInt();
configMonsterItem* hitem =CData::getCData()->getConfigOfMonster(iiiiid);
if(hitem != NULL)
{
dic->setObject(hitem, hitem->nickname);
}
else{
char iii[100] = "";
sprintf(iii, "怪物id不存在 %d",iiiiid);
CCLog(iii);
}
}
char chars[500] = "";
int how = dic->count();
CCArray* arr = dic->allKeys();
switch (how) {
case 1:
sprintf(chars, "【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString());
break;
case 2:
sprintf(chars, "【%s】\n【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(),((CCString*)(arr->objectAtIndex(1)))->getCString());
break;
case 3:
sprintf(chars, "【%s】 【%s】\n【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(),((CCString*)(arr->objectAtIndex(1)))->getCString(),((CCString*)(arr->objectAtIndex(2)))->getCString());
break;
default:
if(how >= 4)
{
sprintf(chars, "【%s】 【%s】\n【%s】 【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(),
((CCString*)(arr->objectAtIndex(1)))->getCString(),
((CCString*)(arr->objectAtIndex(2)))->getCString(),((CCString*)(arr->objectAtIndex(3)))->getCString());
}
break;
}
item->enemydesc = chars;
CCLog(item->enemydesc.c_str());
m_config_map_level_dic->setObject(item, item->bid);
}
}
}
return (MapItem*)m_config_map_level_dic->objectForKey(levelid);
}
示例9: CCAssert
void b2ShapeCache::addShapesWithFile(const std::string &plist, b2Vec2 vertexScale, float ptm) {
CCDictionary *dict = CCDictionary::createWithContentsOfFile(plist.c_str());
CCAssert(dict != NULL, "Shape-file not found");
CCAssert(dict->count() != 0, "plist file empty or not existing");
CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata");
int format = metadataDict->valueForKey("format")->intValue();
ptmRatio = metadataDict->valueForKey("ptm_ratio")->floatValue();
if (ptm <= 0)
ptm = ptmRatio;
CCLOG("ptmRatio = %f",ptmRatio);
CCAssert(format == 1, "Format not supported");
CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies");
b2Vec2 vertices[b2_maxPolygonVertices];
CCDictElement *dictElem;
std::string bodyName;
CCDictionary *bodyData;
//iterate body list
CCDICT_FOREACH(bodyDict,dictElem )
{
bodyData = (CCDictionary*)dictElem->getObject();
bodyName = dictElem->getStrKey();
BodyDef *bodyDef = new BodyDef();
CCPoint a = CCPointFromString(bodyData->valueForKey("anchorpoint")->getCString());
float32 ax = (vertexScale.x >= 0) ? (float32)a.x : (float32)(1-a.x);
float32 ay = (vertexScale.y >= 0) ? (float32)a.y : (float32)(1-a.y);
bodyDef->anchorPoint = b2Vec2(ax, ay);
CCArray *fixtureList = (CCArray*)(bodyData->objectForKey("fixtures"));
FixtureDef **nextFixtureDef = &(bodyDef->fixtures);
//iterate fixture list
CCObject *arrayElem;
CCARRAY_FOREACH(fixtureList, arrayElem)
{
b2FixtureDef basicData;
CCDictionary* fixtureData = (CCDictionary*)arrayElem;
basicData.filter.categoryBits = fixtureData->valueForKey("filter_categoryBits")->intValue();
basicData.filter.maskBits = fixtureData->valueForKey("filter_maskBits")->intValue();
basicData.filter.groupIndex = fixtureData->valueForKey("filter_groupIndex")->intValue();
basicData.friction = fixtureData->valueForKey("friction")->floatValue();
basicData.density = fixtureData->valueForKey("density")->floatValue();
basicData.restitution = fixtureData->valueForKey("restitution")->floatValue();
basicData.isSensor = fixtureData->valueForKey("isSensor")->intValue() != 0;
int callbackData = fixtureData->valueForKey("userdataCbValue")->intValue();
const char* fixtureType = fixtureData->valueForKey("fixture_type")->getCString();
if (strcmp(fixtureType, "POLYGON")==0) {
CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons"));
CCObject *dicArrayElem;
CCARRAY_FOREACH(polygonsArray, dicArrayElem)
{
FixtureDef *fix = new FixtureDef();
fix->fixture = basicData; // copy basic data
fix->callbackData = callbackData;
b2PolygonShape *polyshape = new b2PolygonShape();
int vindex = 0;
CCArray *polygonArray = (CCArray*)dicArrayElem;
assert(polygonArray->count() <= b2_maxPolygonVertices);
CCObject *piter;
CCARRAY_FOREACH(polygonArray, piter)
{
CCString *verStr = (CCString*)piter;
CCPoint offset = CCPointFromString(verStr->getCString());
vertices[vindex] = b2Vec2((float32)(offset.x / ptmRatio) * vertexScale.x, (float32)(offset.y / ptmRatio) * vertexScale.y);
vindex++;
}
示例10: CCAssert
void GB2ShapeCache::addShapesWithFile(const std::string &plist) {
//const char *fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist.c_str()).c_str();
CCDictionary *dict = CCDictionary::createWithContentsOfFile(plist.c_str());
// not triggered - cocos2dx delivers empty dict if non was found
CCAssert(dict != NULL, "Shape-file not found");
CCAssert(dict->count() != 0, "plist file empty or not existing");
CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata");
int format = static_cast<CCString *>(metadataDict->objectForKey("format"))->intValue();
ptmRatio = static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->floatValue();
CCLOG("ptmRatio = %f",ptmRatio);
CCAssert(format == 1, "Format not supported");
CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies");
b2Vec2 vertices[b2_maxPolygonVertices];
CCDictElement *dictElem;
std::string bodyName;
CCDictionary *bodyData;
//iterate body list
CCDICT_FOREACH(bodyDict,dictElem )
{
bodyData = (CCDictionary*)dictElem->getObject();
bodyName = dictElem->getStrKey();
BodyDef *bodyDef = new BodyDef();
bodyDef->anchorPoint = CCPointFromString(static_cast<CCString *>(bodyData->objectForKey("anchorpoint"))->getCString());
CCArray *fixtureList = (CCArray*)(bodyData->objectForKey("fixtures"));
FixtureDef **nextFixtureDef = &(bodyDef->fixtures);
//iterate fixture list
CCObject *arrayElem;
CCARRAY_FOREACH(fixtureList, arrayElem)
{
b2FixtureDef basicData;
CCDictionary* fixtureData = (CCDictionary*)arrayElem;
basicData.filter.categoryBits = static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->intValue();
basicData.filter.maskBits = static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->intValue();
basicData.filter.groupIndex = static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->intValue();
basicData.friction = static_cast<CCString *>(fixtureData->objectForKey("friction"))->floatValue();
basicData.density = static_cast<CCString *>(fixtureData->objectForKey("density"))->floatValue();
basicData.restitution = static_cast<CCString *>(fixtureData->objectForKey("restitution"))->floatValue();
basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->intValue();
CCString *cb = static_cast<CCString *>(fixtureData->objectForKey("userdataCbValue"));
int callbackData = 0;
if (cb)
callbackData = cb->intValue();
std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->m_sString;
if (fixtureType == "POLYGON") {
CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons"));
CCObject *dicArrayElem;
CCARRAY_FOREACH(polygonsArray, dicArrayElem)
{
FixtureDef *fix = new FixtureDef();
fix->fixture = basicData; // copy basic data
fix->callbackData = callbackData;
b2PolygonShape *polyshape = new b2PolygonShape();
int vindex = 0;
CCArray *polygonArray = (CCArray*)dicArrayElem;
assert(polygonArray->count() <= b2_maxPolygonVertices);
CCObject *piter;
CCARRAY_FOREACH(polygonArray, piter)
{
CCString *verStr = (CCString*)piter;
CCPoint offset = CCPointFromString(verStr->getCString());
vertices[vindex].x = (offset.x / ptmRatio) ;
vertices[vindex].y = (offset.y / ptmRatio) ;
vindex++;
}