本文整理汇总了C++中UserDefault::getFloatForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ UserDefault::getFloatForKey方法的具体用法?C++ UserDefault::getFloatForKey怎么用?C++ UserDefault::getFloatForKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefault
的用法示例。
在下文中一共展示了UserDefault::getFloatForKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: displayText
// テキストの表示
void resultText::displayText()
{
// 保存データの読み込み
UserDefault *userDef = UserDefault::getInstance();
float angle = userDef->getFloatForKey("scoreAngle", 0);
float resultAngle = angle;
if ( resultAngle < 0 )
{
resultAngle = resultAngle * (-1);
}
float distance = userDef->getFloatForKey("scoreDistance", 0);
float resultDistance = distance;
// 角度表示
Label *viewAngle = Label::createWithSystemFont("a", "Arial", 50);
viewAngle->setPosition(WINSIZE.width/2, WINSIZE.height/1.2);
addChild(viewAngle);
viewAngle->setString(StringUtils::format("角度:%0.2f°", resultAngle));
log("%0.2f°",resultAngle);
// 距離表示
Label *viewPixel = Label::createWithSystemFont("", "Arial", 50);
viewPixel->setPosition(WINSIZE.width/2, WINSIZE.height/1.37);
addChild(viewPixel);
viewPixel->setString(StringUtils::format("背表紙のりまでの間隔:%0.2fピクセル", resultDistance));
log("%0.2fピクセル", resultDistance);
// 点数表示
Label *viewScore = Label::createWithSystemFont("", "Arial", 50);
viewScore->setPosition(WINSIZE.width/2, WINSIZE.height/1.6);
addChild(viewScore);
viewScore->setString(StringUtils::format("点数:%ld", score));
// 評価文章表示
Label *viewText1 = Label::createWithSystemFont(arrayText[0], "Arial", 27);
viewText1->setPosition(WINSIZE.width/2, 300);
addChild(viewText1);
Label *viewText2 = Label::createWithSystemFont(arrayText[1], "Arial", 27);
viewText2->setPosition(WINSIZE.width/2, 250);
addChild(viewText2);
Label *viewText3 = Label::createWithSystemFont(arrayText[2], "Arial", 27);
viewText3->setPosition(WINSIZE.width/2, 200);
addChild(viewText3);
viewText1->setString(StringUtils::format("プロジェクトマネージャー...%s", arrayText[0].c_str()));
viewText2->setString(StringUtils::format("慇懃無礼な商人...%s", arrayText[1].c_str()));
viewText3->setString(StringUtils::format("C...%s", arrayText[2].c_str()));
log("ラベル配置");
}
示例2: onContactBegin
bool GameScene::onContactBegin(PhysicsContact& contact)
{
auto bodyA = contact.getShapeA()->getBody();
auto bodyB = contact.getShapeB()->getBody();
distanceFromHook = player->getPosition().distance(contact.getShapeA()->getBody()->getPosition());
if ((bodyA->getCategoryBitmask() & bodyB->getCollisionBitmask()) == 0
|| (bodyB->getCategoryBitmask() & bodyA->getCollisionBitmask()) == 0)
{
// Player hits goal
if (bodyA->getTag() == PLAYER && bodyB->getTag() == GOAL)
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
if (!Constant::soundMuted)
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sounds/Goal/IndianWarChant 6077_99.mp3");
}
UserDefault *def = UserDefault::getInstance();
def->getFloatForKey(Constant::mapname.c_str(), highscore);
if (timeMilliseconds < highscore || highscore == 0)
{
highscore = timeMilliseconds;
def->setFloatForKey(Constant::mapname.c_str(), highscore);
}
this->GoToLevelMenuScene(this);
return false;
}
if (bodyB->getTag() == PLAYER && bodyA->getTag() == GOAL)
{
this->GoToLevelMenuScene(this);
return false;
}
// Hook hits player, cancel
if (bodyA->getTag() == PLAYER && bodyB->getTag() == HOOK)
{
return false;
}
if (bodyB->getTag() == PLAYER && bodyA->getTag() == HOOK)
{
return false;
}
// RayBox hits player, cancel
if (bodyA->getTag() == PLAYER && bodyB->getTag() == RAYCASTCOLLISIONBOX)
{
return false;
}
if (bodyB->getTag() == PLAYER && bodyA->getTag() == RAYCASTCOLLISIONBOX)
{
return false;
}
// RayBox hits spikes, cancel
if (bodyA->getTag() == SPIKE && bodyB->getTag() == RAYCASTCOLLISIONBOX)
{
sprite->stopAllActions();
return false;
}
if (bodyB->getTag() == SPIKE && bodyA->getTag() == RAYCASTCOLLISIONBOX)
{
sprite->stopAllActions();
return false;
}
// Player hits spikes, suffer agonizing death.
if (bodyA->getTag() == SPIKE && bodyB->getTag() == PLAYER)
{
this->RestartScene(this);
return false;
}
if (bodyB->getTag() == SPIKE && bodyA->getTag() == PLAYER)
{
this->RestartScene(this);
return false;
}
// // RayBox hits metal, cancel
if (bodyA->getTag() == RAYCASTCOLLISIONBOX && bodyB->getTag() == METAL)
{
sprite->stopAllActions();
return false;
}
if (bodyB->getTag() == RAYCASTCOLLISIONBOX && bodyA->getTag() == METAL)
{
sprite->stopAllActions();
return false;
}
if (sprite)
{
// RayBox hits tiles
if (player->isTouchHold)
{
if (bodyA->getTag() == RAYCASTCOLLISIONBOX && bodyB->getTag() == TILE)
{
sprite->stopAllActions();
boxHitPos = bodyA->getPosition();
//.........这里部分代码省略.........
示例3: rand
Bird::Bird( cocos2d::Layer *layer, b2World *world )
{
visibleSize = Director::getInstance()->getVisibleSize();
int visibleWidth = visibleSize.width;
int visibleHeight = visibleSize.height;
float positionX, positionY;
long whichBird;
auto region = rand() % 4 + 1;
// Adjust random region based on previous regions
UserDefault *def = UserDefault::getInstance();
auto velocity = def->getFloatForKey("velocity", 0);
auto power3_activated = def->getIntegerForKey("power3_activated",0);
auto bird1_region = def->getIntegerForKey("bird1_region", 0);
auto bird2_region = def->getIntegerForKey("bird2_region", 0);
auto blue1 = def->getIntegerForKey("blue1");
auto blue2 = def->getIntegerForKey("blue2");
auto blue3 = def->getIntegerForKey("blue3");
if(bird1_region == 0) {
def->setIntegerForKey("bird1_region", region);
whichBird = 1;
} else {
if(bird2_region == 0){
while(region == bird1_region){
region = rand() % 4 + 1;
}
def->setIntegerForKey("bird2_region", region);
whichBird = 2;
} else {
while(region == bird1_region || region == bird2_region){
region = rand() % 4 + 1;
}
whichBird = 3;
}
}
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
bird = Sprite::create("bird_left.png");
} else {
bird = Sprite::create("blue_left.png");
}
def->flush();
auto rotation = rand() % 46 + 1;
int halfBird = bird->getContentSize().width / 2;
auto birdY = rand() % (visibleHeight - halfBird) + halfBird;
auto birdX = rand() % (visibleWidth - halfBird) + halfBird;
bool top = false;
if(region == 1 || region == 3)
{
if(birdY > visibleHeight / 2){
top = true;
rotation = rand() % 26 + 1;
}
} else {
rotation = rotation + 45;
if(birdX > visibleWidth / 2)
top = true;
}
auto angle = rotation * M_PI / 180;
auto xPos = cos(angle) * (visibleWidth * 1.5);
auto yPos = sin(angle) * (visibleWidth * 1.5);
// Set the bird's position based on region
if(region == 1) // Left
{
bird->setPosition(Point(-halfBird,birdY));
if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
bird->setTexture("bird_right.png");
} else {
bird->setTexture("blue_right.png");
}
if(top) // Above middle of screen
{
bird->setRotation(rotation);
bird->setTag(1);
positionX = bird->getPositionX() + xPos;
positionY = -(bird->getPositionY() + yPos);
}
else // Below middle of screen
{
bird->setRotation(-rotation);
bird->setTag(2);
positionX = bird->getPositionX() + xPos;
positionY = bird->getPositionY() + yPos;
}
}
if(region == 2) // Top
{
bird->setPosition(Point(birdX, visibleHeight + halfBird));
if(top) // Past middle of screen on x axis
{
bird->setRotation(-rotation);
bird->setTag(3);
//.........这里部分代码省略.........
示例4: BeginContact
void MyContactListener::BeginContact(b2Contact* contact)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
UserDefault *def = UserDefault::getInstance();
int visibleWidth = visibleSize.width;
int visibleHeight = visibleSize. height;
int halfVisibleWidth = visibleSize.width / 2;
int halfVisibleHeight = visibleSize.height / 2;
float positionX, positionY;
long whichBird;
b2Body* bird;
b2Body* border;
b2Fixture* a = contact->GetFixtureA();
b2Fixture* b = contact->GetFixtureB();
//make sure only one of the fixtures was a sensor
bool sensorA = a->IsSensor();
bool sensorB = b->IsSensor();
if ( ! (sensorA && sensorB) )
{
if(a->IsSensor()){
bird = a->GetBody();
border = b->GetBody();
whichBird = (long)a->GetUserData();
} else {
border = a->GetBody();
bird = b->GetBody();
whichBird = (long)b->GetUserData();
}
Sprite* birdSprite = (Sprite*)bird->GetUserData();
float birdX = birdSprite->getPositionX();
float birdY = birdSprite->getPositionY();
auto birdTag = birdSprite->getTag();
long borderCheck = (long)border->GetUserData();
auto blue1 = def->getIntegerForKey("blue1");
auto blue2 = def->getIntegerForKey("blue2");
auto blue3 = def->getIntegerForKey("blue3");
auto velocity = def->getFloatForKey("velocity", 0);
auto rotation = rand() % 46 + 1;
bool top = false;
if(borderCheck == 1 || borderCheck == 3) // bottom and right
{
if(birdY > visibleHeight / 2){
top = true;
rotation = rand() % 26 + 1;
}
} else {
rotation = rotation + 45;
if(birdX > visibleWidth / 2)
top = true;
}
auto angle = rotation * M_PI / 180;
auto xPos = cos(angle) * (visibleWidth * 1.5);
auto yPos = sin(angle) * (visibleWidth * 1.5);
// Add missed bird and stop redirection if 3 collisions. GameOver if 3 misses in total
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)))
{
if(whichBird == 1)
{
auto round1_misses = def->getBoolForKey("bird1_missed", 0);
int bird1_collisions = def->getIntegerForKey("bird1_collisions", 0);
bird1_collisions++;
def->setIntegerForKey("bird1_collisions", bird1_collisions);
if(bird1_collisions >= 3 && !round1_misses) {
auto misses = def->getIntegerForKey("misses", 0);
misses++;
def->setIntegerForKey("misses", misses);
auto bird_count = def->getIntegerForKey("bird_count", 0);
bird_count++;
def->setIntegerForKey("bird_count", bird_count);
def->setBoolForKey("bird1_missed", 1);
Director::getInstance()->getEventDispatcher()->removeEventListenersForTarget(birdSprite);
return;
} else {
if(bird1_collisions >= 3) {
return;
}
}
}
if(whichBird == 2)
{
auto round2_misses = def->getBoolForKey("bird2_missed", 0);
int bird2_collisions = def->getIntegerForKey("bird2_collisions", 0);
bird2_collisions++;
def->setIntegerForKey("bird2_collisions", bird2_collisions);
if(bird2_collisions >= 3 && !round2_misses) {
auto misses = def->getIntegerForKey("misses", 0);
misses++;
def->setIntegerForKey("misses", misses);
auto bird_count = def->getIntegerForKey("bird_count", 0);
bird_count++;
def->setIntegerForKey("bird_count", bird_count);
//.........这里部分代码省略.........