代码如下:
start(){
var data=new Uint8Array(256);
data.fill(100);
var rt = new cc.Texture2D();
rt.initWithData(data,cc.Texture2D.PixelFormat.RGBA8888,16,16);
}
预览报错:
CCTexture2D.js:377 Uncaught TypeError: Cannot read property ‘update’ of null
at cc_Texture2D.update (CCTexture2D.js:377)
at cc_Texture2D.update (CCTexture2D.js:377)
at cc_Texture2D.initWithData (CCTexture2D.js:428)
断点源代码:
initWithData (data, pixelFormat, pixelsWidth, pixelsHeight) {
var opts = _getSharedOptions();
opts.image = data;
opts.format = pixelFormat;
opts.width = pixelsWidth;
opts.height = pixelsHeight;
this.update(opts);
this.width = pixelsWidth;
this.height = pixelsHeight;
this.loaded = true;
this.emit(“load”);
return true;
},
然后我从官网链去源码看到的是:
多了这样一段:
if (!this._texture) {
this._texture = new renderer.Texture2D(renderer.device, opts);
}
else {
this._texture.update(opts);
}
所以,请问大大我该怎么办?