为了完整起见,您应该知道可以将多个子对象添加到具有相同标签的对象中。例如,下面的代码将在之后提供日志:
for (NSUInteger i = 0; i < 10; i++) {
CCLabelAtlas *toto = [SpriteUtils mapDamageLabel:23+i];
toto.tag = 901210;
[self addChild:toto z:0 tag:toto.tag];;
}
MPLOG(@"*** remove me : before refresh %@ ***", self.soldier);
for (id child in children_) {
CCNode *ch = (CCNode *) child;
MPLOG(@"<%@> tag: %i name : %@", self.soldier, ch.tag, ch.name);
}
* 现在是日志 *
-[SoldierMapLayout sequenceEngagement:] : * remove me : before refresh red *
-[SoldierMapLayout sequenceEngagement:]:标签:1024 名称:CCSprite:walk_red_rogue_idle0001.png
-[SoldierMapLayout sequenceEngagement:]:标签:891 名称:CCSprite:不能移动
-[SoldierMapLayout sequenceEngagement:]:标签:889 名称:CCSprite:无法治愈
-[SoldierMapLayout sequenceEngagement:] : tag: 890 name : CCSprite : Charmed
-[SoldierMapLayout sequenceEngagement:]:标签:886 名称:CCSprite:健康栏:18
-[SoldierMapLayout sequenceEngagement:]:标签:896 名称:CCSprite:walk_red_rogue_cast0001.png
-[SoldierMapLayout sequenceEngagement:]:标签:895 名称:CCLabelAtlas:致命伤害 16
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 23
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 24
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 25
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 26
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 27
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 28
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 29
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 30
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 31
-[SoldierMapLayout sequenceEngagement:]:标签:901210 名称:CCLabelAtlas:伤害 32
因此,当您稍后执行 [self getChildByTag:901210] 时,CCNode 将返回它找到的第一个带有标签的标签,不一定是您要查找的标签。