这是我的函数。
drawButtons: function() {
gameController.ctx.strokeStyle='pink';
gameController.ctx.fillStyle='rgba(128,128,128,1)';
gameController.ctx.lineWidth=2;
this.roundedRect(gameController.ctx,105,162,160,50,10,true,true);
this.roundedRect(gameController.ctx,105,240,160,50,10,true,true);
gameController.ctx.fillStyle = 'rgba(153,051,000,1)';
gameController.ctx.font = "35px AR DARLING";
gameController.ctx.fillText("1 Player",120,200);
gameController.ctx.fillText("2 Player",120,278);
}
在第一次加载网页时,没有一个被绘制出来。如果有人希望看到,我可以添加代码来显示我在哪里调用该方法。也许我必须添加.onload(),但我只知道如何在画布上添加图像,而不是fillText等。谢谢。
window.onload在我的drawButtons方法中就是解决方案。
drawButtons: function() {
window.onload = (function(){
gameController.ctx.strokeStyle='pink';
gameController.ctx.fillStyle='rgba(128,128,128,1)';
gameController.ctx.lineWidth=2;
nonGameContent.roundedRect(gameController.ctx,105,162,160,50,10,true,true);
nonGameContent.roundedRect(gameController.ctx,105,240,160,50,10,true,true);
gameController.ctx.fillStyle = 'rgba(153,051,000,1)';
gameController.ctx.font = "35px AR DARLING";
gameController.ctx.fillText("1 Player",120,200);
gameController.ctx.fillText("2 Player",120,278);
})},