Question: how to insert a child inside a dynamic node

Question: how to insert a child inside a dynamic node
0

Hi guys and girls,

I’m facing a small problem, but I cannot continue with this. I’m building a leaderboard and I used a for loop for it, here is part of the code:

buildBarInside: function(params){
//var self = this;
let x = - 160, y = - 110, xb = 0, yb = - 120;
this.leaderboard_sprite.node.active = true;
for (var i = 0; i < 5; i++) {
  let yy = i*(y);
  let yv = i*(yb);
  this.buildBackground(cc.v2(xb,yv), i);
  this.buildInside(cc.v2(x, yy), i);
}

},
buildBackground:function(params, name){
//let self = this;
let node = new cc.Node(‘bg’+ name);
let sprite = node.addComponent(cc.Sprite);
node.setScale(1.3);
cc.loader.loadRes(“backgrounds/bg_round_square”, cc.SpriteFrame, function(err,spriteF){
sprite.spriteFrame = spriteF;
});
node.position = params;
//self.scroll_view.node.addChild(node);
this.scroll_view.node.addChild(node);
},
buildInside: function(params, name) {
//let self = this;
let node = new cc.Node();
let sprite = node.addComponent(cc.Sprite);
node.setScale(0.7);
cc.loader.loadRes(“backgrounds/bg_lb_faces”, cc.SpriteFrame, function(err,spriteF){
sprite.spriteFrame = spriteF;
});
node.position = params;
//self.leaderboard_sprite.node.addChild(node);
//this.scroll_view.node.addChild(node);
//this.scroll_view.node.isChildOf(node);
self.scroll_view.node.getComponent(“bg”+ name).addChild(node);
//s_view.node.isChildOf(“bg” + name);

},
Basically I have an error that says :Uncaught TypeError: Cannot read property ‘node’ of undefined

When I try to use the buildInside function with the main node like this: this.scroll_view.node.addChild(node);
It works, but the problem is the Y position of the elements and I’m sure if I insert the elements inside the buildBackground node I won’t need to calibrate position for Y.
Any ideas?
Thanks !

It’ve solved it.
Thanks anyway

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.