本文整理汇总了C++中UserDefault::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ UserDefault::flush方法的具体用法?C++ UserDefault::flush怎么用?C++ UserDefault::flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefault
的用法示例。
在下文中一共展示了UserDefault::flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNetBiosMacAddresses
const std::string CCNative::getDeviceID(void)
{
#define UDID_KEY "__UDID_KEY__"
std::string udid;
UserDefault* userDefault = UserDefault::getInstance();
if( NULL != userDefault )
{
udid = userDefault->getStringForKey( UDID_KEY );
}
if( udid.size() == 0 )
{
//GUID uuid;
//CoCreateGuid(&uuid);
//// Spit the address out
//char mac_addr[18];
//sprintf(mac_addr,"%02X:%02X:%02X:%02X:%02X:%02X",
//uuid.Data4[2],uuid.Data4[3],uuid.Data4[4],
//uuid.Data4[5],uuid.Data4[6],uuid.Data4[7]);
udid = GetNetBiosMacAddresses();
if( userDefault )
{
userDefault->setStringForKey(UDID_KEY, udid);
userDefault->flush();
}
}
return udid;
}
示例2: onPressMusic
void SettingsDialog::onPressMusic(cocos2d::Ref *sender, cocos2d::extension::Control::EventType pControlEvent)
{
if (pControlEvent == Control::EventType::TOUCH_UP_INSIDE)
{
UserDefault *ud = UserDefault::getInstance();
bool value = ud->getBoolForKey("music_enabled", true);
ud->setBoolForKey("music_enabled", !value);
if (value)
{
_checkBoxMusic->removeAllChildren();
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(false);
}
else
{
Label *l = Label::create();
l->setString("X");
l->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
_checkBoxMusic->addChild(l);
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("playing.mp3", true);
}
ud->flush();
}
}
示例3: resetSaveData
void TutorialScene::resetSaveData()
{
const int maxNumMonsters = 3;
const int maxNumKnown = 31;
//データをリセット
//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
UserDefault* def = UserDefault::getInstance();
for (int i = 0; i < maxNumMonsters; i++)
{
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);
}
for (int i = 0; i < maxNumKnown; i++)
{
def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
}
def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);
def->flush();
}
示例4: init
// on "init" you need to initialize your instance
bool GameOverScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto backgroundSprite = Sprite::create("Background.png");
backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
this->addChild(backgroundSprite);
auto retryItem = MenuItemImage::create("Retry Button.png", "Retry Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToGameScene, this));
retryItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 * 3));
auto mainMenuItem = MenuItemImage::create("Menu Button.png", "Menu Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToMainMenuScene, this));
mainMenuItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 ));
auto menu = Menu::create(retryItem, mainMenuItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu);
UserDefault *def = UserDefault::getInstance();
auto highScore = def->getIntegerForKey("HIGHSCORE", 0);
if (score > highScore)
{
highScore = score;
def->setIntegerForKey("HIGHSCORE", highScore);
}
def->flush();
__String *tempScore = __String::createWithFormat("Current : %i", score);
auto currentScore = LabelTTF::create(tempScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
currentScore->setPosition(Point(visibleSize.width * 0.25 + origin.x, visibleSize.height /2 + origin.y ));
this->addChild(currentScore);
__String *temHighpScore = __String::createWithFormat("High : %i", highScore);
auto highScoreLabel = LabelTTF::create(temHighpScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
highScoreLabel->setColor(Color3B::YELLOW);
highScoreLabel->setPosition(Point(visibleSize.width * 0.75 + origin.x, visibleSize.height / 2 + origin.y));
this->addChild(highScoreLabel);
return true;
}
示例5: menuSceneTransition
void TitleScene::menuSceneTransition(cocos2d::Ref *pSender, bool newGame)
{
const int maxNumMonsters = 3;
const int maxNumEquip = 10;
if (newGame)
{
if (Generic::checkSaveData())
{
auto nextScene = TutorialScene::createScene();
auto pScene = TransitionFade::create(1.0f, nextScene);
Director::getInstance()->replaceScene(pScene);
}
else
{
const int maxNumMonsters = 3;
const int maxNumKnown = 31;
//データをリセット
//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
UserDefault* def = UserDefault::getInstance();
for (int i = 0; i < maxNumMonsters; i++)
{
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);
}
for (int i = 0; i < maxNumKnown; i++)
{
def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
}
def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);
def->flush();
auto nextScene = MenuScene::createScene();
auto pScene = TransitionFade::create(1.0f, nextScene);
Director::getInstance()->replaceScene(pScene);
}
return;
}
auto nextScene = MenuScene::createScene();
auto pScene = TransitionFade::create(0.5f, nextScene);
Director::getInstance()->replaceScene(pScene);
}
示例6: setSprite
void NegiSprite::setSprite()
{
this->setPosition(Vec2(WINSIZE.width/2, WINSIZE.height/2));
float setLine = 3.0;
UserDefault *userDef = UserDefault::getInstance();
userDef->setFloatForKey("SetLine", setLine);
userDef->flush();
}
示例7: setSprite
void BookSprite::setSprite()
{
Size visibleSize = WINSIZE;
Vec2 origin = Director::getInstance()->getVisibleOrigin();
this->setPosition(Vec2(WINSIZE.width/1.4, WINSIZE.height/2));
float setLine = 2.2;
UserDefault *userDef = UserDefault::getInstance();
userDef->setFloatForKey("SetLine", setLine);
userDef->flush();
}
示例8: init
bool GameOverScene::init() {
if(!Layer::init()) {
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin();
UserDefault* userScore = UserDefault::getInstance();
if(score >= userScore->getIntegerForKey( "highscore" )) {
userScore->setIntegerForKey( "highscore", score );
}
userScore->flush();
//create background for game over scene
auto background = Sprite::create("FlappyResources/Background.png");
background->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
this->addChild(background);
//create retry item
auto retry = MenuItemImage::create( "FlappyResources/Retry_Button.png", "FlappyResources/Retry_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToGameScene, this) );
retry->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 );
//create quit item
auto quit = MenuItemImage::create( "FlappyResources/Menu_Button.png", "FlappyResources/Menu_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToMainMenuScene, this) );
quit->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 - quit->getContentSize().height * 2);
//create menu
auto menu = Menu::create( retry, quit, NULL );
menu->setPosition( Vec2(0, 0) );
//create label score
auto stringScore = __String::createWithFormat( "Your score: %d", score );
auto labelScore = LabelTTF::create( stringScore->getCString(), "fonts/Marker Belt.ttf", 50 );
labelScore->setPosition( origin.x + labelScore->getContentSize().width, origin.y + visibleSize.height / 2 + labelScore->getContentSize().height * 4 );
labelScore->setFontFillColor( Color3B::YELLOW );
//create label display best score
auto stringBestScore = __String::createWithFormat( "High score: %d", userScore->getIntegerForKey( "highscore" ) );
auto labelHighScore = LabelTTF::create( stringBestScore->getCString(), "fonts/Marker Belt.ttf", 50 );
labelHighScore->setPosition( origin.x + labelScore->getContentSize().width + visibleSize.width / 2, origin.y + visibleSize.height / 2 + labelHighScore->getContentSize().height * 4);
labelHighScore->setFontFillColor( Color3B::RED );
this->addChild( menu );
this->addChild( labelScore );
this->addChild( labelHighScore );
return true;
}
示例9: saveHighScore
//ハイスコア記録・表示
void GameScene::saveHighScore()
{
UserDefault* userDefault = UserDefault::getInstance();
//ハイスコアを取得する
int oldHighScore = userDefault->getIntegerForKey(KEY_HIGHSCORE,0);
if(oldHighScore < m_score)
{
//ハイスコアを保存する
userDefault->setIntegerForKey(KEY_HIGHSCORE, m_score);
userDefault->flush();
//ハイスコアを表示する
showHighScoreLabel();
}
}
示例10: setGameOverData
void BBGameDataManager::setGameOverData(int star, int leftTime)
{
int themeId = m_themeId;
int levelId = m_levelId + 1;
UserDefault* ud = UserDefault::getInstance();
// 更新星级
__String *starkey = __String::createWithFormat("star_%d_%d", m_themeId, m_levelId);
int curStar = ud->getIntegerForKey(starkey->getCString(), 0);
if (curStar < star) {
ud->setIntegerForKey(starkey->getCString(), star);
}
__String *bestkey = __String::createWithFormat("best_%d_%d", m_themeId, m_levelId);
int bestTime = ud->getIntegerForKey(bestkey->getCString(), 0);
if (bestTime == 0 || bestTime > leftTime) {
ud->setIntegerForKey(bestkey->getCString(), leftTime);
}
// 更新关卡进度
int themeIdFramCache = ud->getIntegerForKey("themeId", 1);
int levelIdFramCache = ud->getIntegerForKey("levelId", 1);
if (themeIdFramCache > themeId) {
return;
} else if (themeIdFramCache == themeId) {
if (levelIdFramCache >= levelId) {
return;
}
}
if (levelId > 9) {
// 进入下一个主题
themeId++;
levelId = 1;
}
ud->setIntegerForKey("themeId", themeId);
ud->setIntegerForKey("levelId", levelId);
ud->flush();
}
示例11: buttonYes
/*--------------------------/
Yesボタン生成
/--------------------------*/
void StageSelectActionLayer::buttonYes(cocos2d::Layer* layer,Menu* menu,int tag){
auto buttonYes = MenuItemImage::create("Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
"Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
[ = ](Ref* sender)
{
UserDefault* useDef = UserDefault::getInstance();
useDef->setIntegerForKey("selectStage",tag);
useDef->setIntegerForKey("selectGimmick", tag);
useDef->flush();
auto nextScene = SceneCreator::createPhysicsScene(GameMainScene::create(), Vect(0, -9.8f), 5.0f);
auto scene = TransitionFade::create( 1.5f, nextScene, Color3B::BLACK );
auto dir = Director::getInstance();
dir->replaceScene(scene);
});
buttonYes->setPosition(400,300);
buttonYes->setScale(1.2f);
menu->addChild(buttonYes);
}
示例12: setControllerType
void GeneralUtils::setControllerType(ControllerType controllerType)
{
int controllerTypeInt = 0;
if (controllerType == E_CONTROLLER_TOUCH)
{
controllerTypeInt = 1;
}
else if (controllerType == E_CONTROLLER_TILT)
{
controllerTypeInt = 2;
}
else
{
return;
}
UserDefault *ud = UserDefault::getInstance();
ud->setIntegerForKey("control_type", controllerTypeInt);
ud->flush();
}
示例13: onPressSound
void SettingsDialog::onPressSound(cocos2d::Ref *sender, cocos2d::extension::Control::EventType pControlEvent)
{
if (pControlEvent == Control::EventType::TOUCH_UP_INSIDE)
{
UserDefault *ud = UserDefault::getInstance();
bool value = ud->getBoolForKey("sound_enabled", true);
ud->setBoolForKey("sound_enabled", !value);
if (value)
{
_checkBoxSound->removeAllChildren();
}
else
{
Label *l = Label::create();
l->setString("X");
l->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
_checkBoxSound->addChild(l);
}
ud->flush();
}
}
示例14: onHttpRequestCompleted
//Callback
void TrivialAPI::onHttpRequestCompleted(HttpClient* client, HttpResponse* response)
{
const char *responseTag;
if (!response)
return;
if (!response->isSucceed())
{
log("response failed");
log("error buffer: %s", response->getErrorBuffer());
log("HTTP Status Code: %ld", response->getResponseCode());
std::vector<char> *buffer = response->getResponseData();
printf("Http Test, dump data: ");
for (unsigned int i = 0; i < buffer->size(); i++)
{
printf("%c", (*buffer)[i]);
}
printf("\n");
UserDefault *pUserDefaults = UserDefault::getInstance();
std::string hash = pUserDefaults->getStringForKey("hash");
if (hash.length() == 0) {
MessageBox("Interneta beharrezkoa da", "Error");
} else {
_finishCalbback->execute();
}
} else {
responseTag = response->getHttpRequest()->getTag();
int statusCode = (int) response->getResponseCode();
char statusString[64] = {};
sprintf(statusString, "HTTP Status Code: %d, tag = %s", statusCode, responseTag);
//log(statusString);
}
std::vector<char> *buffer = response->getResponseData();
std::string str(buffer->begin(), buffer->end());
if (!strcmp(responseTag, "generalToken")) {
UserDefault *pUserDefault = UserDefault::getInstance();
std::string savedHash = pUserDefault->getStringForKey("hash");
std::string token = parseGeneralToken(str);
if (savedHash.compare(token) != 0) {
_hash = token;
_sqlHelper->resetDB();
updateKategoriak(emptyPrivateCode);
} else {
//updatePrivateData();
_finishCalbback->execute();
}
} else if(!strcmp(responseTag, "kategoriak")) {
parseKategoriak(str);
updateMultzoak(emptyPrivateCode);
} else if(!strcmp(responseTag, "multzoak")) {
parseMultzoak(str);
updateGalderak(emptyPrivateCode);
} else if(!strcmp(responseTag, "galderak")) {
parseGalderak(str);
UserDefault *pUserDefault = UserDefault::getInstance();
std::string savedHash = pUserDefault->getStringForKey("hash");
if (savedHash.empty()) {
_sqlHelper->initUserData();
} else {
_sqlHelper->updateUserData();
}
pUserDefault->setStringForKey("hash", _hash);
pUserDefault->flush();
//updatePrivateData();
_finishCalbback->execute();
}
}
示例15: BeginContact
//.........这里部分代码省略.........
{
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_left.png");
} else {
birdSprite->setTexture("blue_left.png");
}
birdSprite->setTag(7);
birdSprite->setRotation(rotation);
positionX = -(birdX + xPos);
positionY = birdY + yPos;
} else {
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_right.png");
} else {
birdSprite->setTexture("blue_right.png");
}
birdSprite->setTag(8);
birdSprite->setRotation(-rotation);
positionX = birdX + xPos;
positionY = birdY + yPos;
}
} else { // Left
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_right.png");
} else {
birdSprite->setTexture("blue_right.png");
}
if( birdY > halfVisibleHeight )
{
birdSprite->setTag(1);
birdSprite->setRotation(rotation);
positionX = birdX + xPos;
positionY = -(birdY + yPos);
} else {
birdSprite->setTag(2);
birdSprite->setRotation(-rotation);
positionX = birdX + xPos;
positionY = birdY + yPos;
}
}
}
if((birdTag == 6 || birdTag == 7) && (borderCheck == 2 || borderCheck == 4)) // RightBottom || BottomRight -> top and left
{
if(borderCheck == 2) // Top
{
if( birdX > halfVisibleWidth )
{
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_left.png");
} else {
birdSprite->setTexture("blue_left.png");
}
birdSprite->setTag(3);
birdSprite->setRotation(-rotation);
positionX = -(birdX + xPos);
positionY = -(birdY + yPos);
} else {
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_right.png");
} else {
birdSprite->setTexture("blue_right.png");
}
birdSprite->setTag(4);
birdSprite->setRotation(rotation);
positionX = birdX + xPos;
positionY = -(birdY + yPos);
}
} else { // Left
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
birdSprite->setTexture("bird_right.png");
} else {
birdSprite->setTexture("blue_right.png");
}
if( birdY > halfVisibleHeight )
{
birdSprite->setTag(1);
birdSprite->setRotation(rotation);
positionX = birdX + xPos;
positionY = -(birdY + yPos);
} else {
birdSprite->setTag(2);
birdSprite->setRotation(-rotation);
positionX = birdX + xPos;
positionY = birdY + yPos;
}
}
}
if(((birdTag == 1 || birdTag == 4) && (borderCheck == 1 || borderCheck == 3)) || ((birdTag == 2 || birdTag == 8) && (borderCheck == 2 || borderCheck == 3)) || ((birdTag == 3 || birdTag == 5) && (borderCheck == 1 || borderCheck == 4)) || ((birdTag == 6 || birdTag == 7) && (borderCheck == 2 || borderCheck == 4)))
{
bird->SetLinearVelocity( b2Vec2(positionX * velocity / PTM_RATIO, positionY * velocity / PTM_RATIO));
}
def->flush();
contact->SetEnabled(false);
}
}