Cocos2d-x game Archive

Source: Internet
Author: User

The game archiving function can store game data so that gamers can continue the game. Single-host games are even more important. CCUserDefault can be used as a lightweight database to store data. It supports the data types bool, int, float, double, string.

Store Data

CCUserDefault: sharedUserDefault ()-> setStringForKey ("string", "value1"); // Parameter order: Key, corresponding value: CCUserDefault: sharedUserDefault () -> setIntegerForKey ("integer", 10); CCUserDefault: sharedUserDefault ()-> setFloatForKey ("float", 2.3f); CCUserDefault: sharedUserDefault () -> setDoubleForKey ("double", 2.4); CCUserDefault: sharedUserDefault ()-> setBoolForKey ("bool", true );


Obtain the above data output

String str = CCUserDefault: sharedUserDefault ()-> getStringForKey ("string"); // parameter: CCLOG ("str: % s", str. c_str (); int I = CCUserDefault: sharedUserDefault ()-> getIntegerForKey ("integer"); CCLOG ("I: % d", I); float f = CCUserDefault:: sharedUserDefault ()-> getFloatForKey ("float"); CCLOG ("f: % f", f); double d = CCUserDefault: sharedUserDefault () -> getDoubleForKey ("double"); CCLOG ("d: % f", d); bool B = CCUserDefault: sharedUserDefault ()-> getBoolForKey ("bool "); if (B) CCLOG ("bool is true"); elseCCLOG ("bool is false ");


Modify data

CCUserDefault: sharedUserDefault ()-> setStringForKey ("string", "test"); // modify the CCUserDefault: sharedUserDefault ()-> setFloatForKey ("float ", 3.1413); // modify float data string str1 = CCUserDefault: sharedUserDefault ()-> getStringForKey ("string"); CCLOG ("str1: % s ", str1.c _ str (); float f2 = CCUserDefault: sharedUserDefault ()-> getFloatForKey ("float"); CCLOG ("f2: % f", f2 );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.