第一次加载时绘制到画布失败.刷新后就可以工作了
drawing to canvas fails on first load. Refresh and it works
这是我的函数。
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);
})},
相关文章:
- PHP和JS脚本的奇怪问题,在我刷新页面之前第一次失败
- Jquery选择菜单选项在页面刷新时失败
- 登录失败时不刷新
- AngularJS:cookie 在浏览器刷新时失败
- 第一次加载时绘制到画布失败.刷新后就可以工作了
- JavaScript仅在Chrome中刷新后失败
- Ajax调用有时工作,有时工作和刷新,有时刷新和失败....
- Firefox失败-使用文档后.写入和更新位置.哈希导致页面刷新
- 在页面刷新时,单元测试在通过和失败之间交替进行
- Ruby on Rails在使用ajax刷新页面时失败
- 如何刷新jwt并重新发送失败的http请求
- AngularJS html5Mode刷新失败
- jQueryUI可排序刷新失败
- Javascript会间歇性地失败,但在页面刷新时可以正常工作
- 刷新令牌是如何工作的,以及上次失败的http请求是如何再次调用的,给出401.
- 表单提交第一次失败,并在刷新页面时工作
- jsTree 在第二次刷新时失败
- 尝试使用AJAX提交而不刷新,静默失败
- 提交失败后刷新jquery表单
- 如果iframe刷新失败,则X