CCUserDefault 存档

复制代码
void HelloWorld::testCCUserDefault()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCLabelTTF* ttf = CCLabelTTF::create(" ", "Helvetica", 30);
    ttf->setPosition(ccp(size.width/2, size.height/2));
    addChild(ttf);

    if (CCUserDefault::sharedUserDefault()->getBoolForKey("bool",false))
    {
        ttf->setString("No user data");
        //Load
        bool isBool = CCUserDefault::sharedUserDefault()->getBoolForKey("bool", false);
        double isDouble = CCUserDefault::sharedUserDefault()->getDoubleForKey("double", 0.0);
        float isFloat = CCUserDefault::sharedUserDefault()->getFloatForKey("float", 0.0f);
        int isInt = CCUserDefault::sharedUserDefault()->getIntegerForKey("int", 0);
        std::string isString = CCUserDefault::sharedUserDefault()->getStringForKey("string", "");

        CCLOG("%b__%d__%f__%f__%i__%s",isBool,isDouble,isFloat,isInt,isString.c_str());

    }else{
        ttf->setString("load user data");

        CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);
        CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 998.0);
        CCUserDefault::sharedUserDefault()->setFloatForKey("float", 888.0f);
        CCUserDefault::sharedUserDefault()->setIntegerForKey("int", 88);
        CCUserDefault::sharedUserDefault()->setStringForKey("string", "Xff");

        //提交
        CCUserDefault::sharedUserDefault()->flush();

    }
    
}
复制代码

生成文件  UserDefault.xml

 

 

 

posted @   解放1949  阅读(441)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示