【问题标题】:How to use sqlite database in cocos creator javascript如何在 cocos creator javascript 中使用 sqlite 数据库
【发布时间】:2017-02-08 16:00:10
【问题描述】:

我想为我的问答游戏使用本地数据库文件,例如问题数据库。我在 cocos creator 官方网站或论坛上找不到任何教程。在 c++ 中已经解决了这个问题
Use database (such as sqlite) with cocos2d-x
但是我想在下面的javascript中使用它,这是Cocos creator中的默认脚本

cc.Class({
extends: cc.Component,

properties: {
    // foo: {
    //    default: null,      // The default value will be used only when the component attaching
    //                           to a node for the first time
    //    url: cc.Texture2D,  // optional, default is typeof default
    //    serializable: true, // optional, default is true
    //    visible: true,      // optional, default is true
    //    displayName: 'Foo', // optional
    //    readonly: false,    // optional, default is false
    // },
    // ...
},

// use this for initialization
onLoad: function () {

},

onbuttnclick: function(){
    //var test = new cc.Scene('test');
    //cc.director.pushScene(test);
    cc.director.loadScene('helloworld');
    //cc.director.popScene();
},

// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },
});

我需要 javascript 的解决方案,因为我的 c++ 很差

【问题讨论】:

    标签: javascript android sqlite cocoscreator


    【解决方案1】:

    在 cocoscreator 中,它有本地保存的 api,如 h5 localstorage.set 获取参数是键值,键我忘记了 api,但关键是它像 h5 localstorage api,它会在本机中自动使用 sqlite

    【讨论】:

    • 对不起第一个命令。因为我用电话回复没有代码。现在我检查你可以使用它的代码如下:cc.sys.localStorage.setItem("key","value"); let value = cc.sys.localStorage.getItem("key");你可以存储任何 JSON.stringify(JSONObject);作为localStorage中的值,如果您不删除本地磁盘中的数据文件或chrome中的本地缓存,则在重新启动游戏时随时获取它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多