Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML画布的文本未显示在屏幕上_Javascript_Html_Canvas - Fatal编程技术网

Javascript HTML画布的文本未显示在屏幕上

Javascript HTML画布的文本未显示在屏幕上,javascript,html,canvas,Javascript,Html,Canvas,当我尝试在我的HTML画布上为我正在开发的游戏显示文本时,它没有出现。这很奇怪,因为对于另一个类似的项目来说,它工作得很好。如有任何建议,将不胜感激 并不是说scoreText不存在,或者说文本不存在,它与在画布上绘制有关 var游戏片; var=[]; var得分=0; 文本; 函数起始名{ 游戏件=新组件30,30,红色,10,120; scoreText=新组件30px,控制台,黑色,280,80,文本; myGameArea.start; } var myGameArea={ 画布:d

当我尝试在我的HTML画布上为我正在开发的游戏显示文本时,它没有出现。这很奇怪,因为对于另一个类似的项目来说,它工作得很好。如有任何建议,将不胜感激

并不是说scoreText不存在,或者说文本不存在,它与在画布上绘制有关

var游戏片; var=[]; var得分=0; 文本; 函数起始名{ 游戏件=新组件30,30,红色,10,120; scoreText=新组件30px,控制台,黑色,280,80,文本; myGameArea.start; } var myGameArea={ 画布:document.createElementcanvas, 开始:功能{ this.canvas.width=window.screen.width; this.canvas.height=window.screen.height-100; this.context=this.canvas.getContext2d; document.body.insertBeforethis.canvas,document.body.childNodes[0]; 这个.frameNo=0; this.interval=setIntervalueUpdateGameArea,20; window.addEventListener'mousemove',函数e{ myGameArea.x=e.pageX; myGameArea.y=e.pageY; }; }, 清除:功能{ this.context.clearRect0,0,this.canvas.width,this.canvas.height; } } 函数everyintervaln{ 如果myGameArea.frameNo/n%1==0{ 返回true; } 返回false; } 功能组件宽度、高度、颜色、x、y{ 这个。宽度=宽度; 高度=高度; 这是0.speedX=0; 该值为0; 这个.x=x; 这个。y=y; this.update=函数{ ctx=myGameArea.context; 如果this.type==text{ ctx.font=this.width++this.height; ctx.fillStyle=颜色; ctx.filltexthis.text,this.x,this.y; }否则{ ctx.fillStyle=颜色; ctx.beginPath; ctx.arcthis.x,this.y,this.width/2,0,2*Math.PI; ctx.fill; } } this.newPos=函数{ this.x+=this.speedX; this.y+=this.speedY; } this.crashWith=functionobj{ var mycenter=this.x+this.width/2; var mycentry=this.y+this.height/2; var oCenterX=对象x+对象宽度/2; 变量Ocentry=对象y+对象高度/2; var-crash=false; 如果Math.sqrtMath.powmycentrex-ocentrex,2+Math.powmycentrey-ocentrey,2 var游戏片; var=[]; var得分=0; 文本; 函数起始名{ 游戏件=新组件30,30,红色,10,120; scoreText=新组件30px,控制台,黑色,280,80,文本; myGameArea.start; } var myGameArea={ 画布:document.createElementcanvas, 开始:功能{ this.canvas.width=window.screen.width; this.canvas.height=window.screen.height-100; this.context=this.canvas.getContext2d; document.body.insertBeforethis.canvas,document.body.childNodes[0]; 这个.frameNo=0; this.interval=setIntervalueUpdateGameArea,20; window.addEventListener'mousemove',函数e{ myGameArea.x=e.pageX; myGameArea.y=e.pageY; }; }, 清除:功能{ this.context.clearRect0,0,this.canvas.width,this.canvas.height; } } 函数everyintervaln{ 如果myGameArea.frameNo/n%1==0{ 返回true; } 返回false; } //在这里添加类型参数 功能组件宽度、高度、颜色、x、y、类型{ this.type=type;//此处将其设置为组件实例 这个。宽度=宽度; 高度=高度; 这是0.speedX=0; 该值为0; 这个.x=x; 这个。y=y; this.update=函数{ ctx=myGameArea.context; 如果this.type==text{ ctx.font=this.width++this.height; ctx.fillStyle=颜色; ctx.filltexthis.text,this.x,this.y; }否则{ ctx.fillStyle=颜色; ctx.beginPath; ctx.arcthis.x,this.y,this.width/2,0,2*Math.PI; ctx.fill; } } this.newPos=函数{ this.x+=this.speedX; this.y+=this.speedY; } this.crashWith=functionobj{ var mycenter=this.x+this.width/2; 菌丝体变种= 这个.y+这个.height/2; var oCenterX=对象x+对象宽度/2; 变量Ocentry=对象y+对象高度/2; var-crash=false; 如果Math.sqrtMath.powmycentrex-ocentrex,2+Math.powmycentrey-ocentrey,2}浏览器中Javascript控制台上有任何错误/警告吗?