允许用户在HTML5 Canvas游戏中键入文本 [英] Allowing the user to type text in a HTML5 Canvas game

查看:112
本文介绍了允许用户在HTML5 Canvas游戏中键入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Canvas和优秀的KineticJS库的组合编写我的第一个HTML5游戏,我早点打了一点墙。



我想要做的是要求用户在游戏中的框中输入他们的名字。做了一些研究,我不能看到任何方式这样做之外获得一个浮动HTML元素在我使用的画布的那部分。



这是正确的?



在许多Flash和网络游戏上长大后,我确信每次我必须输入一个名称或保存文件名,游戏本身,它不依赖于HTML来生成它?



任何有关如何做的建议都将非常感谢。


可以使用以下CSS技术在画布顶部获取浮动HTML元素。 http://css-tricks.com/absolute-positioning-inside-relative-定位/





这适用于所有HTML元素,而不仅仅是canvas。


I'm trying to write my first HTML5 game using a combination of Canvas and the excellent KineticJS library and I've hit a bit of a wall early on.

What I want to do is ask the user to enter their name in a box in the game. Having done some research, i can't see any way of doing this outside getting a floating HTML element over that part of the canvas I'm using.

Is this correct?

Having grown up on a lot of Flash and web games, I'm sure each time I have to input a name or save file name, it's done directly into the game itself and it doesn't rely on the HTML to generate it?

Any advice on how to do this would be gratefully received.

解决方案

You can get a floating HTML element on the top of canvas using the following CSS technique.

http://css-tricks.com/absolute-positioning-inside-relative-positioning/

This applies for all HTML elements, not just canvas.

这篇关于允许用户在HTML5 Canvas游戏中键入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆