cocoscreator 使用内置自带的资源和生成单色图片

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值