Getting child from tag

Getting child from tag
0.0 0


Hello, I have a, I think, simple issue. I’m trying to get a childNode by using it’s tag. I have a function that is called several times:

    if(!this.hasPath) return;

        var drawPrefab = cc.instantiate(this.drawPathNode);

    var drawPrefab = this.node.getChildByTag(111);

As you can see, I create a childNode when the function is called and the ‘positionOnPath’ variable is set to ‘1’. The position get incremented elsewhere then the function is called again. I am wanting something different to happen when the position is not ‘1’ and I’m trying to update the childNode I created previously but I am unable to reference it. This is why I’m trying to use the getChildByTag feature.

Is there something obvious that I am doing wrong here?

Thanks in advance!


Nvm. I was able to change the code,


And that worked.


if you want to set a tag while adding the child in the same function it would be

this.node.addChild(drawPrefab,1, 111);

1 is the z-order and 111 is the tag.


Oh, okay. That makes sense. Cool. Thanks!