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
Dreams are one of those things that keep you going and happy!!!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步