简体   繁体   English

HTML5画布不显示文本

[英]HTML5 Canvas not displaying text

I'm learning some game dev with JavaScript, so I wanted to use HTML5 canvas to draw on the screen. 我正在学习一些使用JavaScript的游戏开发者,因此我想使用HTML5画布在屏幕上绘制。 The problem is that I can't get it to display text. 问题是我无法显示文本。 You can see my code here (you might be greeted by a prompt asking a name for your chatracter) http://jsfiddle.net/LAmC3/ 您可以在这里看到我的代码(可能会提示您输入牵引车的名称,从而引起欢迎) http://jsfiddle.net/LAmC3/

Essentially i only used: 基本上我只使用了:

canX.font = '80pt Helvetica';
canX.fillText(player.getName(),100, 100);

With canX being the context of my canvas which has the same dimensions as the viewport. 使用canX作为画布的上下文,画布的尺寸与视口相同。

If anyone knows why, please let me know. 如果有人知道为什么,请告诉我。

您正在以与背景相同的颜色绘制文本,将fillStyle设置为新的内容,例如

canX.fillStyle = '#FFFFFF';

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

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