如何在 Phaser 中进行文本输入?

How to take text input in Phaser?

我正在使用 Phaser 制作一个 HTML5 游戏,我想将玩家名称作为输入并保存以备后用 我如何使用 Phaser 进行此操作?

您可以做很多选择,但是 windows 提示

呢?
var player = prompt("Please enter your name", "name");

然后你可以通过本地存储保存它

localStorage.setItem("playerName", player);

如果以后想用的话

localStorage.getItem("playerName");

在我的游戏中我使用了模态 (http://getbootstrap.com/javascript/#modals) to allow user input name. I also implemented leaderboard. To save users and scores (+times) I integrated with parse (https://www.parse.com/)

工作示例:http://majery.pl/memo/

我从未见过 HTML 重叠处理文本的 Flash 游戏。我预计随着 Javscript 游戏引擎的发展,它们最终会发现它们还需要处理 canvas 内的渲染文本。好消息是这项工作已经开始。 https://github.com/goldfire/CanvasInput

<script src="CanvasInput.min.js"></script>

<script>
    var bmd = this.add.bitmapData(400, 50);    
    var myInput = this.game.add.sprite(15, 15, bmd);

    myInput.canvasInput = new CanvasInput({
        canvas: bmd.canvas,
    });
    myInput.inputEnabled = true;
    myInput.input.useHandCursor = true;    
</script>

Phaser 和 CanvasInput 演示可以在这里看到,http://codepen.io/jdnichollsc/pen/waVMdB?editors=001

一个缺点是您必须使用 Phaser.CANVAS 而不是 Phaser.AUTO 在 Phaser 中使用 canvas 渲染。

更新:有人也做了这个https://github.com/orange-games/phaser-input

考虑将 CanvasInput library. It creates native canvas-based inputs and is very easy utilize. You add it to your create method and continue from there. Here's an example 与 Phaser 一起使用。