gpt4 book ai didi

javascript - 如何使用 Cocos2D-JS 将变量保存到 Android?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:06 24 4
gpt4 key购买 nike

我正在尝试将高分整数保存到用户的 Android 系统,以便它可以在所有游戏体验中持续存在。

我读到使用 Cocos2D-X 可以使用 NSUserDefaults 但这似乎在 Cocos2D-JS API 中根本不可用。

谁有这方面的经验,有没有其他有效的方法来解决这个问题?

最佳答案

当使用 Cocos2D-JS 编译原生应用时,你可以简单地使用 localStorage 就像你在浏览器中运行你的游戏一样:D

例如:

//Handle for quick access to Cocos2D's implementation of Local Storage:
var ls = cc.sys.localStorage;

var value = "foo";
var key = "bar";

//This should save value "foo" on key "bar" on Local Storage
ls.setItem(key, value);

//This should read the content associated with key "bar" from Local Storage:
var data = ls.getItem(key);

cc.log(data); //Should output "foo" to the console.

//This should remove the contents of key "bar" from Local Storage:
ls.removeItem(key);

//This should print "null"
data = ls.getItem(key);
cc.log(data);

关于javascript - 如何使用 Cocos2D-JS 将变量保存到 Android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26242672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com