1: 加载内置的effect和material的资源
cc.assetManager.builtins.getBuiltin("material", "builtin-" + name)
cc.assetManager.builtins.getBuiltin("effect", "builtin-" + name)
2:因为有些内置的资源打包的时候是不打到包里的,不能通过cc.assetManager.internal.get的方式获取,这种的可以通过预制体的方式解决或者直接复制一分图片在自己的resources目录里
3:动态生成单色的图片, 4个255对应的是rgba的值,需要注意的是,rgba一般调成白色255,不然,node节点设置颜色时会无效
let node = new cc.Node();
let texture = new cc.Texture2D();
let spriteFrame = new cc.SpriteFrame();
let imgWidth = 1;
let imgHeight = 1;
let count = imgWidth * imgHeight * 4;
let imgData =new Uint8Array(count);
for (var j = 0; j < count; j += 4) {
imgData[j] = 255 // r
imgData[j + 1] = 255 // g
imgData[j + 2] = 255 // b
imgData[j + 3] = 255 // a
}
texture.initWithData(imgData, cc.Texture2D.PixelFormat.RGBA8888, imgWidth, imgHeight);
// texture.initWithData(new Uint8Array([255,255,255,255]), cc.Texture2D.PixelFormat.RGBA8888, 1, 1);
spriteFrame.setTexture(texture);
spriteFrame.setRect(cc.rect(0, 0, 100, 100));
// spriteFrame.setRect(cc.rect(0, 0, width, height));
node.addComponent(cc.Sprite).spriteFrame = spriteFrame;
return node