DATA_OLD/Cocos2d-x 기능성 게임 개발과정
[D_013] 간단한 데이터 저장방법 UserDefault
웽웽
2014. 11. 27. 15:29
UserDefault
key와 value를 이용하여, key 값에 value를 저장하는 방식.
보안이 따로 필요없는 간단한 데이터들을 로컬에 저장한 뒤 불러오는 방식의 저장소.
getIntegerForKey로 불러오고, setIntegerForKey로 저장한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | void HelloWorld::setScore() { auto label = (Label*)this->getChildByTag(TAG_LABEL_SCORE); label->setString(StringUtils::format("SCORE : %d", score)); auto high = (Label*)this->getChildByTag(TAG_LABEL_HIGHSCORE); high->setString(StringUtils::format("HIGHSCORE : %d", UserDefault::getInstance()->getIntegerForKey("HIGHSCORE"))); if (score >= highest) { highest = score; UserDefault::getInstance()->setIntegerForKey("HIGHSCORE", highest); high->setString(StringUtils::format("HIGH SCORE : %d", highest)); CCLOG("update highest"); } } |