记录一下遇到的问题及解决方案.
原因: WebGL context 没申请 stencil(模板)缓冲。微信 PC 端(和 iOS 高性能模式)下,WebGL
默认不开启 stencil,而 cc.Mask 依赖 stencil 测试做裁剪 → stencil buffer 没启用 → 遮罩内容白屏。
解决方案: 在微信初始化前,手动用 stencil: true 获取一次 WebGL context :
在game.js 中加入:
var sysInfo = wx.getSystemInfoSync();
if (sysInfo.platform === ‘windows’ || sysInfo.platform === ‘mac’ || sysInfo.isPC) {
GameGlobal.canvas.getContext(‘webgl’, { stencil: true });
}