for (let i = 0; i < 5; i++) {
let node = new cc.Node();
const sprite = node.addComponent(cc.Sprite);
if (i < 2) {
cc.loader.loadRes('ui-heart', cc.SpriteFrame, function(err, spriteFrame) {
sprite.spriteFrame = spriteFrame;
});
} else {
cc.loader.loadRes('ui-heart-gray', cc.SpriteFrame, function(err, spriteFrame) {
sprite.spriteFrame = spriteFrame;
});
}
node.setPosition(cc.v2(heartPos.x += 45, heartPos.y));
node.parent = that.heart_box;
}
先确定你要循环几次,加载本地的图片精灵,记得放在动态加载的图片要放在resources目录下,再把循环的精灵挂载在heart_box节点上
加粗样式
获取到父组件,想修改该组件下的子组件
//克隆goods_item节点
var node = cc.instantiate(that.goods_item);
node.getChildByName('gold-item-content').getChildByName('gold-title').getComponent(cc.Label).string = "123";