Uncaught TypeError: Cannot read property 'LineCap' of undefined

Uncaught TypeError: Cannot read property ‘LineCap’ of undefined

// 代码段

start: function () {
if (cc.director.setClearColor) {
cc.director.setClearColor( cc.hexToColor(’#01aaff’) );
}

    this.time = 0;

    this.ctx = this.getComponent("cc.Graphics");
    this.ctx.lineCap = cc.Graphics.LineCap.BUTT;
    this.ctx.lineJoin = cc.Graphics.LineJoin.ROUND;

    let waves = this.waves;
    for (let i = 0, l = waves.length; i < l; i++) {
        waves[i].waveFn = Waves[Waves.Enum[waves[i].waveType]].bind(Waves);
        waves[i].easeFn = Ease[Ease.Enum[waves[i].easeType]].bind(Ease);
    }
},

估计是你的节点上没有添加cc.Graphics组件,this.ctx=this.getComponent(“cc.Graphics”)的时候得到的是undefined,下一行this.ctx.lineCap就会报这个错误,无法读取undefined的属性LineCap。你加这样一行试试:

this.ctx = this.getComponent("cc.Graphics");
if (!this.ctx) {
    this.ctx = this.addComponent("cc.Graphics");
}
this.ctx.lineCap = cc.Graphics.LineCap.BUTT;

cc.Graphics.LineCap 这个空,不是左边空

cc.Graphics 未定义,可能是老版本还不支持这个功能,也有可能是运行时裁剪掉了引擎的这个模块,请检查模块设置。

已经查到问题了。模块设置的地方被我取消了。
但是这个实在太坑,模拟器下跑是没问题的,build之后有问题,我觉得官方还是应该保持开发模式和发布模式环境一致。

原型和开发阶段经常会导入不同的组件尝试效果,如果预览也会报错的话测试起来会很蛋疼。

我感觉您说的这个场景 通常情况只有 creator的研发团队需要,对于开发者而言,在creator里面是正常的,发布出来,需要走公司流程,邮件各种,然后再给到运营同事。或者即便是在测试环境中,也需要不少操作,等部署好了,发现有bug。程序同学会自己的环境 又发现没问题,极有可能会消耗不必要的时间 进行定位 ,最终修复,然后再把刚才的流程走一遍。简直想哭。。。