
尽管cocos2dx里面CCUserDefault这个类,但是我觉得不太好用,因为,使用的时候,需要每次都指定类型,字符串、整型,不是很方便。
我是用了,之前分享代码里面的overload方式,使得工具代码的使用者无需关心具体的细节,只要知道自己要保存什么,和默认的值是什么就行了
[1].[代码][Lua]代码跳至[1] ?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | getpref = overloaded() function getpref . string . number(key,defaultVal) local userdata = CCUserDefault:sharedUserDefault() local v = userdata:getStringForKey(key,"") v= tonumber(v) if not v then v =defaultVal end return v end boolean (key,defaultVal) local userdata = CCUserDefault:sharedUserDefault() return userdata:getBoolForKey(key,defaultVal) end string val ) local userdata = CCUserDefault:sharedUserDefault() userdata:setStringForKey(key,tostring( )) end ) local userdata = CCUserDefault:sharedUserDefault() userdata:setBoolForKey(key,monospace!important; Font-size:1em!important; min-height:inherit!important">) end ) local userdata = CCUserDefault:sharedUserDefault() ) end |
以上是内存溢出为你收集整理的cocos2dx配置信息保存全部内容,希望文章能够帮你解决cocos2dx配置信息保存所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)