Original Work, reprinted, please mark: Http://blog.csdn.net/jackystudio/article/details/12036237
Int score; // Real-Time score
Static int highestHistoryScore; // The highest historical score.
// Add scorescoreItem = CCLabelBMFont: create ("0", "font/font. fnt "); // scoreItem is a member variable of the CCLabelBMFont * type. The Custom font is used here, the first article provides scoreItem-> setColor (ccc3 (143,146,147); scoreItem-> setAnchorPoint (ccp (0, 0.5 )); scoreItem-> setPosition (ccp (pPauseItem-> getPositionX () + normalPause-> getContentSize (). width/2 + 5, pPauseItem-> getPositionY (); this-> addChild (scoreItem );
// Update the score void ControlLayer: updateScore (int score) {if (score> = 0 & score <= MAX_SCORE) // you can set a maximum value of 2 billion {CCString * strScore = CCString:: createWithFormat ("% d", score); // format it as a string scoreItem-> setString (strScore-> m_sString.c_str (); // obtain char * From CCString *, update score }}
// If life = 1, remove enemy3, else if (enemy3-> life = 1) {enemy3-> life --; mutiBulletsToDelete-> addObject (mutiBullets ); enemy3sToDelete-> addObject (enemy3); score + = ENEMY3_SCORE; // increase the score. ENMEY3_SCORE is a macro, the value is the score obtained by shooting down enemy 3. this-> controlLayer-> updateScore (score); // call the updateScore update score of ControlLayer}
Bool WelcomeLayer: isHaveSaveFile () // determine whether the archive exists {if (! CCUserDefault: sharedUserDefault ()-> getBoolForKey ("isHaveSaveFileXml") // you can use the configured bool flag bit to determine whether {CCUserDefault: sharedUserDefault () exists () -> setBoolForKey ("isHaveSaveFileXml", true); // write the bool judgment bit CCUserDefault: sharedUserDefault ()-> setIntegerForKey ("HighestScore", 0 ); // write the initial score 0 CCUserDefault: sharedUserDefault ()-> flush (); // call flush after setting to write data from the buffer to ioreturn false ;} else {return true ;}} void WelcomeLayer: equals () {if (isHaveSaveFile () // if an archive exists {GameOverLayer: highestHistoryScore = CCUserDefault: sharedUserDefault () -> getIntegerForKey ("HighestScore", 0); // the highest score for reading history }}
// Call if (score> highestHistoryScore) {CCUserDefault: sharedUserDefault ()-> setIntegerForKey ("HighestScore", score) in the GameOver layer ); // modify the archive highestHistoryScore = score // reset the highest score... there are other things later}
What should we do?
:
< p>