0
안드로이드 개발로 시작한 이래로 오랜 시간이 걸렸습니다. 게임을 설정하고 모든 것이 제대로 작동하는 시점에서 고생했습니다. 최고 점수가 업데이트되고 최신 최고 점수는 GameOverScene
에도 표시됩니다. 그러나 목록을 만들고 싶었습니다. 상위 5 개 최고점을 말하고 단지 복수 점을 UserDefault
에 저장할 수는 없습니다.cocos2d-x : userdefault에서 리더 보드 점수 절약
여기서는 GameOverScene
이 호출되고 currentScore
이 전달됩니다.
auto scene = GameOverScene::createScene(currentScore);
GameScene.cpp 그런 다음 GameOverScene.cpp
에 나는이
GameOverScene.cpp
class GameOverScene : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene(unsigned int tempScore);
currentScore = tempScore;
// rest of the code
}
bool GameOverScene::init()
{
..//
UserDefault *defScore = UserDefault::getInstance();
// auto highScore[] = defScore->getIntegerForKey("HIGH SCORE", 0);
auto highScore = defScore->getIntegerForKey("HIGH SCORE", 0);
// for(int i=0; i<=5; i++){
if(currentScore > highScore)
{
highScore = currentScore;
log("high score inside IF: %i", highScore);
defScore->setIntegerForKey("HIGH SCORE", highScore);
}
// }
defScore->flush();
__String *tempScore = __String::createWithFormat("%i", currentScore);
auto cScoreLabel = LabelTTF::create(tempScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
cScoreLabel->setPosition(Point(visibleSize.width * 0.25 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(cScoreLabel);
// for(int i=0; i < =5; i++){
__String *tempHighScore = __String::createWithFormat("%i", highScore);
auto highScoreLabel = LabelTTF::create(tempHighScore->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;
}