[英]Canvas Not Rendering Properly: Why?
I was trying to construct an RPG out of html5 and Javascript with the <canvas>
element; 我试图用<canvas>
元素用html5和Javascript构建一个RPG; but I ran across a real stumper of an error: my code does not modify the <canvas>
element at all. 但我遇到了一个错误的真正困境:我的代码根本不修改<canvas>
元素。
<!DOCTYPE html>
<head>
<title>BoxRPG</title>
</head>
<body>
<h3>Box RPG</h3>
<canvas id="rpgCanvas" width = "200" height = "100" style = "border:1px solid #FF0000;">failMessage</canvas>
<script type = "text/javascript">
var c = document.getElementById("rpgCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#000000";
</script>
</body>
</html>
I cannot for the life of me figure out this! 我不能为我的生活搞清楚这一点! Am I just being stupid and missing the obvious or is there some deeper problem with either code or my system. 我只是愚蠢而且错过了明显的问题,或者是代码或我的系统存在更深层次的问题。
fill style is not a fill command , you have to specify area to fill : 填充样式不是填充命令,您必须指定要填充的区域:
var c = document.getElementById("rpgCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
http://fiddle.jshell.net/ms7Lg/ http://fiddle.jshell.net/ms7Lg/
if you seek advice , leave this all and start learning 如果您寻求建议,请留下这一切并开始学习
http://jonobr1.github.io/two.js/ http://jonobr1.github.io/two.js/
or maybe 或者可能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.