【发布时间】:2015-10-23 07:39:15
【问题描述】:
我在 Backbone 上开发了 HTML5 游戏。当您想使用编辑菜单和编辑世界时,它使用本地存储。您也可以使用此菜单更改您的角色。所以我想在游戏开始前添加角色选择,但我真的不知道如何将它插入到文件中。 文件如下所示:
3:"{"viewportBottom":0,"id":3,"tiles":[],"x":0,"y":0,"tileWidth":32,"tileHeight":32,"width":212,"height":17,"backgroundColor":"rgba(66, 66, 255, 1)","name":"level_1-1","sprites":[
{"name":"ground-ug","state":"idle","sequenceIndex":0,"x":32,"y":512},
{"name":"ground-ug","state":"idle","sequenceIndex":0,"x":0,"y":512},
{"name":"ground-ug","state":"idle","sequenceIndex":0,"x":64,"y":512},
{"name":"ground-ug","state":"idle","sequenceIndex":0,"x":128,"y":512},
{"name":"luigi","state":"idle-right","sequenceIndex":0,"x":192,"y":448,"velocity":0,"acceleration":0,"yVelocity":0,"yAcceleration":0}
],"savedOn":"2015-07-31T14:29:08.725Z","state":"play","viewportTop":0,"viewportRight":0,"viewportLeft":0,"time":748}"
例如,我想把 Luigi 换成马里奥,但我真的很菜鸟。
<p id="Character" onclick="choose('mario')">Mario</p>
<script>
var character;
function choose(choice){
character = choice;
}
var parsed = JSON.parse(myJSONData, function(k, v) {
if (v === "mario")
this.value = character;
else
return v;
});
}
</script>
顺便说一句,它不起作用:D 我也不知道如何将它存储到本地存储中。我正在查看文档,但我并不聪明:D 这个基于 Backbone 的游戏的文档:http://martindrapeau.github.io/backbone-game-engine/
有人能帮帮我吗? :) 谢谢。
【问题讨论】:
-
那是怎么回事。使用 json 解析保存游戏统计数据的对象。并将其保存在本地存储中,因为本地存储只接受键值对。
标签: javascript json html backbone.js local-storage