Class cc.UserDefault
- Defined in: CCUserDefault.js
- Extends cc.Class
Constructor Attributes | Constructor Name and Description |
---|---|
cc.UserDefault acts as a tiny localStorage. |
Method Summary
Class Detail
cc.UserDefault()
cc.UserDefault acts as a tiny localStorage. You can save and get base type values by it.
For example, setBoolForKey("played", true) will add a bool value true into the localStorage.
Its key is "played". You can get the value of the key by getBoolForKey("played").
It supports the following base types:
bool, int, float, double, string
Method Detail
-
{Boolean} getBoolForKey(key, defaultValue)Get bool value by key, if the key doesn't exist, a default value will return.
You can set the default value, or it is false.- Parameters:
- {String} key
- {Boolean} defaultValue
- Returns:
- {Boolean}
-
{Number} getDoubleForKey(key, defaultValue)Get double value by key, if the key doesn't exist, a default value will return.
You can set the default value, or it is 0.0.- Parameters:
- {String} key
- {Number} defaultValue
- Returns:
- {Number}
-
{Number} getFloatForKey(key, defaultValue)Get float value by key, if the key doesn't exist, a default value will return.
You can set the default value, or it is 0.0f.- Parameters:
- {String} key
- {Number} defaultValue
- Returns:
- {Number}
-
returns a shared instance of the UserDefault
- Returns:
- {cc.UserDefault|}
-
{Number} getIntegerForKey(key, defaultValue)Get integer value by key, if the key doesn't exist, a default value will return.
You can set the default value, or it is 0.- Parameters:
- {String} key
- {Number} defaultValue
- Returns:
- {Number}
-
{String} getStringForKey(key, defaultValue)Get string value by key, if the key doesn't exist, a default value will return.
You can set the default value, or it is "".- Parameters:
- {String} key
- {String} defaultValue
- Returns:
- {String}
-
purge a shared instance of the UserDefault
- Returns:
- {cc.UserDefault|}
-
setBoolForKey(key, value)Set bool value by key.
- Parameters:
- {String} key
- {Boolean} value
-
setDoubleForKey(key, value)Set double value by key.
- Parameters:
- {String} key
- {Number} value
-
setFloatForKey(key, value)Set float value by key.
- Parameters:
- {String} key
- {Number} value
-
setIntegerForKey(key, value)Set integer value by key.
- Parameters:
- {String} key
- {Number} value
-
setStringForKey(key, value)Set string value by key.
- Parameters:
- {String} key
- {String} value