Cocos2d-x Game Archive

Source: Internet
Author: User

Game archive allows you to save in-game data. Allows the player to continue the game. A single game is more important. Ccuserdefault can be used as a lightweight database to store data, support data types Bool,int, float, double, string.

Storing data

Ccuserdefault::shareduserdefault ()->setstringforkey ("string", "value1"); Order of parameters: key. The corresponding value Ccuserdefault::shareduserdefault ()->setintegerforkey ("integer", 10); Ccuserdefault::shareduserdefault ()->setfloatforkey ("float", 2.3f); Ccuserdefault::shareduserdefault ()->setdoubleforkey ("Double", 2.4); Ccuserdefault::shareduserdefault ()->setboolforkey ("bool", true);

Get the above data output

String str = Ccuserdefault::shareduserdefault ()->getstringforkey ("string");//Parameters: Returns the key value Cclog ("str:%s") based on the key passed in, STR.C _str ()); int i = Ccuserdefault::shareduserdefault ()->getintegerforkey ("integer"); Cclog ("I:%d", i), float f = ccuserdefault::shareduserdefault ()->getfloatforkey ("float"); Cclog ("F:%f", f);d ouble 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");

Change data

Ccuserdefault::shareduserdefault ()->setstringforkey ("string", "test"); Change the string Data Ccuserdefault::shareduserdefault ()->setfloatforkey ("float", 3.1413);  Change the float data string str1 = Ccuserdefault::shareduserdefault ()->getstringforkey ("string"); Cclog ("str1:%s", Str1.c_str ()), float F2 =ccuserdefault::shareduserdefault ()->getfloatforkey ("float"); Cclog ("F2:%f", F2);

Cocos2d-x Game Archive

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: 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.