正如其中一条评论所述,一个ID为“cr-stage”的div对crafty.js很重要。但是,你并不需要包含它。如果你不发表,它会自动创建。
<html>
<head>
<!-- this is the crafty.js library, which you could load from another server -->
<script src="crafty.js"></script>
<!-- this is the script where all your game's JS goes -->
<script src="mygame.js"></script>
<script>
window.addEventListener('load', Game.start);
</script>
</head>
<body>
</body>
</html>
如果您使用上述内容,您将获得为您创建的cr-stage id。
另一件可能与你的问题相关的事情是,如果你想要中心cr阶段,并删除自动出现在它上面的一个小缺口。要做到这一点,请使用以下代码:
<html>
<head>
<!-- this is the crafty.js library, which you could load from another server -->
<script src="crafty.js"></script>
<!-- this is the script where all your game's JS goes -->
<script src="mygame.js"></script>
<script>
window.addEventListener('load', Game.start);
</script>
<style type="text/css">
/* remove the small gap at the top */
body { margin-top: 0 }
/* horizontally center your stage on the page */
#cr-stage { margin: 0 auto 0 }
</style>
</head>
<body>
</body>
</html>
来源
2013-05-28 20:36:18
jep
这不是它的工作原理;通常,代码将决定它将在哪里创建新元素。事实上,你在div中添加脚本是无关紧要的。 – bfavaretto 2013-04-06 01:38:39
所以它会在我使用的游戏框架的Javascript中的某个地方? – 2013-04-06 01:40:19
可能。请添加框架的名称和链接到文档的问题,它应该帮助我们找到解决方案。 – bfavaretto 2013-04-06 01:43:23