daihovey
daihovey

Reputation: 3575

Check if a CCSprite is added to the Layer

I want to be able to check if the sprite has been added (using [self addChild]) to my Layer.

Is there a BOOL like sprite.isAdded or something similar? Or do I have to search through the array of children in the layer?

Upvotes: 0

Views: 1673

Answers (2)

Mythili
Mythili

Reputation: 189

While adding your child, you can set the tag.

define ktag 1

CCSprite *sprite=[CCSprite spriteWithFile:@"xxx.png"];
sprite.position=ccp(200,200);
[self addChild:sprite tag:ktag];

if you want to check, u can use [self getChildbyTag:ktag]

Upvotes: 4

Minakshi
Minakshi

Reputation: 1433

if you are adding it properly then it will definitely get added and accordingly will appear on the layer. Anyways why you need to check? Though I am new to cocos2d, as per my searching there no such way to check the sprite is added or not.

Upvotes: 0

Related Questions