Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

cocos creator localstorage

// Save data
cc.sys.localStorage.setItem(key, value)

cc.sys.localStorage.setItem('gold', 100);

// For complex data as object, we can first serialize it to JSON:
userData = {
    name: 'Tracer',
    level: 1,
    gold: 100
};

cc.sys.localStorage.setItem('userData', JSON.stringify(userData));

// Read data
cc.sys.localStorage.getItem(key)

var userData = JSON.parse(cc.sys.localStorage.getItem('userData'));
 
PREVIOUS NEXT
Tagged: #cocos #creator #localstorage
ADD COMMENT
Topic
Name
2+3 =