简体   繁体   English

将文本字段添加到画布HTML5

[英]Add textfield to canvas HTML5

I am creating a browser game with JavaScript and I want for the user to type his nickname before the game starts. 我正在用JavaScript创建一个浏览器游戏,我希望用户在游戏开始前输入昵称。 How it is possible to add a textfield to the canvas? 如何在画布上添加文本框? I tried with an overlay to the canvas. 我尝试在画布上覆盖一层。 But I can not remove it with javascript. 但是我无法使用javascript删除它。

Thank you in advande for your advices. 感谢您的先进建议。

Ok guys I found a solution for my question. 好的,我为我的问题找到了解决方案。 I am using the createjs framework that offers me the possibility to create DOM Elemets and place them on the canvas. 我正在使用createjs框架,该框架使我可以创建DOM Elemets并将其放置在画布上。 So I have done it like this: 所以我这样做是这样的:

        var domElement = new createjs.DOMElement(document.getElementById('nickname'));
        domElement.x = 650;
        domElement.y = - domElement.height;
        this.stage.addChild(domElement);

My HTML code is this: 我的HTML代码是这样的:

<div id="canvas_wrap">
<form id="myForm" style="visibility: hidden">
    <input id="nickname" value="Your nickname!" size="10">
</form>

<canvas id="display" width="1280" height="800"></canvas>
<!--<div id="overlay" style="color:#ff3f3a;width: 1280px;height: 800px; visibility:hidden">  -->
<div id="overlay" style="color:#ff3f3a;">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM