首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绘制到画布在第一次加载时失败。刷新,它就可以工作了

绘制到画布在第一次加载时失败。刷新,它就可以工作了
EN

Stack Overflow用户
提问于 2013-07-25 21:05:19
回答 1查看 68关注 0票数 0

这是我的函数。

代码语言:javascript
复制
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等。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-07-25 21:47:00

我的drawButtons方法中的window.onload就是解决方案。

代码语言:javascript
复制
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);
    })},
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17858876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档