Hi,
I’m using Cocos2dx 2.2.2, and I don’t find a way to save values other then CCString using a CCDictionary.
I will also need to save a CCarray with integers, do I need to convert all to CCString?
Here is my code
void GameStatus::saveGame()
{
CCDictionary * myDictionary = new CCDictionary();
CCString testValue1 ="ABC";
myDictionary->setObject(&testValue1,"test_key1");
CCInteger testValue2 = 5;
myDictionary->setObject( &testValue2,"test_key2" );
CCFloat testValue3 = 2.5f;
myDictionary->setObject( &testValue3,"test_key3" );
CCBool testValue4 = false;
myDictionary->setObject( &testValue4,"test_key4" );
std::string _path = CCFileUtils::sharedFileUtils()->getWritablePath();
_path.append ("GameData.plist");
if( myDictionary->writeToFile(_path.c_str()))
CCLOG("Written");
else
CCLOG("Written falied");
myDictionary->release();
}
Saved File Contents
<?xml version="1.0" encoding="UTF-8"?> test_key1 ABC test_key2 test_key3 test_key4Thanks