使用 Node.js 开始使用 Phaser

  1. 创建一个你想要让你的游戏生效的文件夹,然后进入该文件夹
mkdir my-new-game
cd my-new-game
  1. 使用 npm 初始化目录。
npm init -y
  1. 将 phaser 安装为节点包。
npm install phaser
  1. 将 http-server 安装为全局模块,以在命令行上使用。
npm install -g http-server
  1. 创建一个 index.html 文件并引用 Phaser 可执行文件并将以下代码粘贴到其中。
<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>My Gamer</title>
    <script type="text/javascript" src="node_modules/phaser/build/phaser.js"></script>
    <style type="text/css">
    body {
        margin: 0;
    }
    </style>
</head>

<body>
    <div id="helloWorld"></div>
</body>
<script>
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'helloWorld', {
    create: create
});

function create() {

    var text = "Hello World!";
    var style = {
        font: "65px Arial",
        fill: "#ff0044",
        align: "center"
    };

    var t = game.add.text(game.world.centerX, 300, text, style);
    t.anchor.set(0.5);

}
</script>

</html>
  1. 启动服务器并在浏览器中加载 http:// localhost:8080
    hs