本文整理汇总了C++中CCUserDefault::setIntegerForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CCUserDefault::setIntegerForKey方法的具体用法?C++ CCUserDefault::setIntegerForKey怎么用?C++ CCUserDefault::setIntegerForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCUserDefault
的用法示例。
在下文中一共展示了CCUserDefault::setIntegerForKey方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool MainScene::init()
{
CCSize winSize = Director::getInstance()->getVisibleSize();
if (!CCLayer::init())
{
return false;
}
auto BackGround = Sprite::create("backg.png");
BackGround->setPosition(ccp(winSize.width / 2, winSize.height / 2)); //위치지정
this->addChild(BackGround);
CCMenu *MenuMain = CCMenu::create(NULL); //메뉴생성
CCMenu *MenuMain1 = CCMenu::create(NULL); //메뉴생성
CCMenu *MenuMain2 = CCMenu::create(NULL); //메뉴생성
//메뉴아이템 추가
CCMenuItem *item1 = CCMenuItemImage::create("start.png",
"start.png",
this,
menu_selector(MainScene::menuCloseCallback));
CCMenuItem *item2 = CCMenuItemImage::create("rank.png",
"rank.png",
this,
menu_selector(MainScene::RankCloseCallback));
CCMenuItem *item3 = CCMenuItemImage::create("create.png",
"create.png",
this,
menu_selector(MainScene::CreaterMenuCallback));
MenuMain->addChild(item1, 1); //메뉴에 아이템 붙이기
MenuMain1->addChild(item2, 2);
MenuMain2->addChild(item3, 3);
MenuMain->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 20));
MenuMain1->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 90));
MenuMain2->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 160));
this->addChild(MenuMain, 1);
this->addChild(MenuMain1, 2);
this->addChild(MenuMain2, 3);//메뉴를 레이어에 추가
CCUserDefault* user = CCUserDefault::sharedUserDefault();
int SaveSw = CCUserDefault::sharedUserDefault()->getIntegerForKey("SaveMake");
if (SaveSw == 0){
user->setIntegerForKey("SaveMake", 1);
user->setIntegerForKey("Rank1", 0);
user->setIntegerForKey("Rank2", 0);
user->setIntegerForKey("Rank3", 0);
user->setIntegerForKey("Rank4", 0);
user->setIntegerForKey("Rank5", 0);
}
return true;
}
示例2: writeRuntimeDataToLocal
void LocalData::writeRuntimeDataToLocal()
{
CCUserDefault* userDefault = CCUserDefault::sharedUserDefault();
userDefault->setBoolForKey("hasmusic", RunTimeData::getInstance()->hasMusic);
userDefault->setBoolForKey("guiderecord", RunTimeData::getInstance()->isFirstTime);
userDefault->setStringForKey("levelStarStr", RunTimeData::getInstance()->levelStars);
userDefault->setIntegerForKey("passedLevelNum", RunTimeData::getInstance()->passedLevel);
userDefault->setIntegerForKey("totalStarNum", RunTimeData::getInstance()->startNum);
userDefault->setIntegerForKey("annihilator", RunTimeData::getInstance()->annihilatorNum);
userDefault->setBoolForKey("isFirstTime", RunTimeData::getInstance()->isFirstTime);
userDefault->flush();
}
示例3: flush
void Config::flush() {
CCUserDefault* ud = CCUserDefault::sharedUserDefault();
ud->setBoolForKey(CONFIG_KEY_MUTE, m_mute);
ud->setBoolForKey(CONFIG_KEY_HASSAVEDPUZZLE, m_hasSavedPuzzle);
ud->setIntegerForKey(CONFIG_KEY_HIGHSCORE, m_highScore);
ud->setIntegerForKey(CONFIG_KEY_HIGHLEVEL, m_highLevel);
ud->setIntegerForKey(CONFIG_KEY_SAVEDSCORE, m_savedScore);
ud->setIntegerForKey(CONFIG_KEY_SAVEDTARGET, m_savedTarget);
ud->setIntegerForKey(CONFIG_KEY_SAVEDLEVEL, m_savedLevel);
ud->setIntegerForKey(CONFIG_KEY_SAVEDROW, m_savedRow);
ud->setIntegerForKey(CONFIG_KEY_SAVEDCOL, m_savedCol);
ud->setStringForKey(CONFIG_KEY_SAVEDPUZZLE, m_savedPuzzle);
ud->flush();
}
示例4: setTutorialProgress
void GameConfig::setTutorialProgress(PH::TutorialProgress progress)
{
tutorialMode = progress;
CCUserDefault* user = CCUserDefault::sharedUserDefault();
user->setIntegerForKey(CONFIG_TUTORIAL_PROGRESS, tutorialMode);
user->flush();
}
示例5: save
void GameConfig::save()
{
std::string playerUID = PlayerData::getInstance()->player->uid;
CCUserDefault* user = CCUserDefault::sharedUserDefault();
user->setBoolForKey((playerUID + "_instance_stage").c_str(),
showInstanceStage);
user->setBoolForKey((playerUID + "_soul_exchange").c_str(),
showSoulExchange);
user->setBoolForKey((playerUID + "_shuffle_relation").c_str(),
showShuffleRelation);
user->setBoolForKey((playerUID + "_first_time_neili").c_str(),
firstTimeNeili);
user->setBoolForKey((playerUID + "_first_time_instance").c_str(),
firstTimeShowInstance);
user->setBoolForKey((playerUID + "_first_time_zhuansheng").c_str(),
firstTimeZhuansheng);
user->setIntegerForKey((playerUID + "_open_instance").c_str(), openInstanceStep);
user->setBoolForKey((playerUID + "_open_jueding10").c_str(), openJueDing10);
user->setBoolForKey((playerUID + "_show_drag_hint").c_str(), showDragHint);
user->setBoolForKey((playerUID + "_show_attr_hint").c_str(), showAttrHint);
user->flush();
}
示例6: saveSettings
void GameData::saveSettings()
{
#if (ANDROIDSAVEBYUSERDEFAULT == 1 && CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JNI_setBool("IsBeginner", gd_isBeginner);
JNI_setInt("HighScore", gd_highScore);
JNI_setInt("Gold", gd_gold);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCUserDefault* write = CCUserDefault::sharedUserDefault();
write->setBoolForKey("IsBeginner", gd_isBeginner);
write->setIntegerForKey("HighScore", gd_highScore);
write->setIntegerForKey("Gold", gd_gold);
write->flush();
#endif
}
示例7: saveScore
void GameScene::saveScore()
{
CCUserDefault* ud = CCUserDefault::sharedUserDefault();
int rank;
for( rank=1; rank<= 5 ; ++rank){
char key[4];
sprintf( key, "Score%dth", rank);
int score = ud->getIntegerForKey(key,0);
if( score < m_score )
break;
}
for( int i = 5; i > rank ; --i){
char key_src[4];
sprintf( key_src, "Score%dth", i-1);
char key_dst[4];
sprintf( key_dst, "Score%dth", i);
ud->setIntegerForKey(key_dst, ud->getIntegerForKey(key_src,0));
}
char key[4];
sprintf( key, "Score%dth", rank);
ud->setIntegerForKey(key, m_score);
CCSprite* crown = NULL;
switch(rank){
case 1:
crown = CCSprite::create("crown_gold.png");
break;
case 2:
crown = CCSprite::create("crown_silver.png");
break;
case 3:
crown = CCSprite::create("crown_bronze.png");
break;
}
if( crown ){
crown->setPosition(ccp(m_winSize.width/2,m_winSize.height * 0.7));
crown->setOpacity(0);
crown->setScale(0);
this->addChild(crown,kZOrderScore,kTagCrown);
CCDelayTime* delay = CCDelayTime::create(0.8f);
CCFadeIn* fadein = CCFadeIn::create(0.5f);
CCScaleTo* zoomin = CCScaleTo::create(0.5f,1.0f);
CCCallFuncN* callfunc = CCCallFuncN::create(this,callfuncN_selector(GameScene::callSkewAnim));
crown->runAction(CCSequence::create(delay, CCSpawn::createWithTwoActions(fadein, zoomin),callfunc,NULL));
}
}
示例8: saveSettings
void GameData::saveSettings()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
CCUserDefault* write = CCUserDefault::sharedUserDefault();
write->setBoolForKey("IsExisted", _isExisted);
write->setIntegerForKey("HighScore", _highScore);
write->flush();
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
JNI_setBool("IsExisted", _isExisted);
JNI_setInt("HighScore", _highScore);
#endif
}
示例9: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
float fx = winSize.width / DESIGN_RESOLUTION_WIDTH;
float fy = winSize.height / DESIGN_RESOLUTION_HEIGHT;
if (fx > fy)
g_fResScale = fx;
else
g_fResScale = fy;
// create a scene. it's an autorelease object
// run
CCUserDefault* userdata = CCUserDefault::sharedUserDefault();
if (!userdata->getIntegerForKey(LEVEL))
{
userdata->setIntegerForKey(LEVEL, 1);
}
CCScene *pScene = LogoScene::scene();
pDirector->runWithScene(pScene);
// pDirector->runWithScene(CarGame::scene());
// pDirector->runWithScene(NinjaScene::scene());
return true;
}
示例10: setCurrentLevel
void Level::setCurrentLevel(int number) {
CCUserDefault* db = CCUserDefault::sharedUserDefault();
db->setIntegerForKey(CURRENT_LEVEL_KEY, number);
db->flush();
}
示例11: storeData
void Logic::storeData() {
CCUserDefault *u = CCUserDefault::sharedUserDefault();
u->setStringForKey("loginName", loginName);
u->setStringForKey("nickname", nickname);
u->setIntegerForKey("uid", uid);
}
示例12: init
// Initialize our Main Menu Layer, and add the initial main menu with the title screen, play button and about button.
bool GameOverLayer::init()
{
// Initialize the parent
if (!CCLayer::init()) return false;
// Load the high scores
CCUserDefault *store = CCUserDefault::sharedUserDefault();
int bestScore = store->getIntegerForKey("best-score", 0);
int bestDistance = store->getIntegerForKey("best-distance", 0);
int bestDifficulty = store->getIntegerForKey("best-difficulty", 0);
bool newRecord = false;
if (GameManager::sharedGameManager()->getScore() > bestScore && GameManager::sharedGameManager()->getDistance() > bestDistance)
{
bestScore = GameManager::sharedGameManager()->getScore();
bestDistance = GameManager::sharedGameManager()->getDistance();
bestDifficulty = GameManager::sharedGameManager()->getDifficulty();
store->setIntegerForKey("best-score", bestScore);
store->setIntegerForKey("best-distance", bestDistance);
store->setIntegerForKey("best-difficulty", bestDifficulty);
store->flush();
newRecord = true;
}
// Set the screen size to the full dimensions of the device (full screen)
this->setContentSize(SCREEN_SIZE);
float labelScaleText = 1.2f;
if (GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid854x480 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x480 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x400 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid720x480)
{
labelScaleText = 0.9f;
}
else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeNormal)
{
labelScaleText = 1.0f;
}
else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeSmall)
{
labelScaleText = 0.5f;
}
CCSprite *gameOverTitle = CCSprite::createWithSpriteFrameName("game_over.png");
gameOverTitle->setScale(0.9f);
gameOverTitle->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.8));
this->addChild(gameOverTitle);
CCString *score = CCString::createWithFormat("YOUR SCORE: %i", GameManager::sharedGameManager()->getScore());
CCLabelBMFont *scoreLabel = CCLabelBMFont::create(score->getCString(), "myGlyphs.fnt");
scoreLabel->setScale(labelScaleText);
scoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.65));
this->addChild(scoreLabel);
CCString *distance = CCString::createWithFormat("YOUR DISTANCE: %i", GameManager::sharedGameManager()->getDistance());
CCLabelBMFont *distanceLabel = CCLabelBMFont::create(distance->getCString(), "myGlyphs.fnt");
distanceLabel->setScale(labelScaleText);
distanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.59));
this->addChild(distanceLabel);
CCString *ydifficulty;
switch (GameManager::sharedGameManager()->getDifficulty())
{
case 3:
ydifficulty = CCString::create("HARD");
break;
case 2:
ydifficulty = CCString::create("MEDIUM");
break;
default:
ydifficulty = CCString::create("EASY");
}
CCString *difficulty = CCString::createWithFormat("YOUR DIFFICULTY: %s", ydifficulty->getCString());
CCLabelBMFont *difficultyLabel = CCLabelBMFont::create(difficulty->getCString(), "myGlyphs.fnt");
difficultyLabel->setScale(labelScaleText);
difficultyLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.53));
this->addChild(difficultyLabel);
CCString *highScore = CCString::createWithFormat("HIGH SCORE: %i", bestScore);
CCLabelBMFont *highScoreLabel = CCLabelBMFont::create(highScore->getCString(), "myGlyphs.fnt");
highScoreLabel->setScale(labelScaleText);
highScoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.43));
this->addChild(highScoreLabel);
CCString *highDistance = CCString::createWithFormat("BEST DISTANCE: %i", bestDistance);
CCLabelBMFont *highDistanceLabel = CCLabelBMFont::create(highDistance->getCString(), "myGlyphs.fnt");
highDistanceLabel->setScale(labelScaleText);
highDistanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.37));
this->addChild(highDistanceLabel);
CCString *bdifficulty;
switch (bestDifficulty)
{
case 3:
bdifficulty = CCString::create("HARD");
break;
case 2:
//.........这里部分代码省略.........
示例13: requestFinished
void SGWelComeLayer::requestFinished(int msgid, CCObject *data)
{
CCLOG("收到数据");
switch (msgid)
{
case MSG_HTTP_FAST_LOGIN:
{
std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
short serverpost = (short)CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
//记录服务器ip和端口号
SGMainManager::shareMain()->setServerInfo(CCString::create(serverip.c_str()) , serverpost);
//连接socket
SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() , serverpost);
}
break;
case MSG_HTTP_LOGIN:
{
int isLogin = SGMainManager::shareMain()->getIsFBLogin();
if (isLogin != 1 || !SGMainManager::shareMain()->getIsFbAutologin())
{
std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
int serverpost = CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() ,(short)serverpost);
}
else
{
SGMainManager::shareMain()->setIsFbAutologin(false);
}
}
break;
case MSg_HTTP_SERVERLIST:
{
SGServerListLayer *box = SGServerListLayer::create(this, (CCArray *)data, SGServerListLayerComeFromFirst);
SGMainManager::shareMain()->showBox(box,false);
}
break;
case MSG_HTTP_UPDATE_SERVER_STATE:
{
CCDictionary *dict = (CCDictionary*)data;
CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
CCString *serverId = (CCString*)dict->objectForKey("serverId");
CCString *serverShowId = (CCString*)dict->objectForKey("serverShowId");
CCString* serverName = (CCString*)dict->objectForKey("serverName");
//保存即将登陆的服务器的描述
serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
//save ip and post of server
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverShowId", serverShowId->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
CCUserDefault::sharedUserDefault()->flush();
CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
changeServerbtn->setFont(serverName->getCString());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
//如果是维护中 则不再登陆。
short serverState = (short)( ( (CCString *)dict->objectForKey("serverState") )->intValue() );
if (1 != serverState)
{
;
}
//提示不能登陆的详细信息。
else
{
SGMainManager::shareMain()->showMessage(serverDes.c_str());
}
//MM: 即使维护中,也尝试登录,101用户会自动放过。
this->realLogin();
}
break;
case MSg_HTTP_LASTESTSERVER:
{
CCDictionary *dict = (CCDictionary*)data;
CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
CCString *serverId = (CCString*)dict->objectForKey("serverId");
CCString* serverName = (CCString*)dict->objectForKey("serverName");
//保存即将登陆的服务器的描述
serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
//save ip and post of server
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
CCUserDefault::sharedUserDefault()->flush();
CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
//.........这里部分代码省略.........