正如其中一条评论所提到的,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-stage 居中并移除一个自动出现在其上方的小间隙。为此,请使用以下代码:
<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>