in A.h i write like this
@interface A
{
CCSprite *loadingSprite;
}
- (void)getTag;
@property (nonatomic, retain) CCSprite *loadingSprite;
@end
then in implementation A.m
@synthesize loadingSprite
- (id)init
{
loadingSprite = [CCSprite spriteWithSpriteFrameName:@"loading-icon1.png"];
[loadingSprite setTag:111];
[self addChild:loadingSprite];
}
- (void)getTag
{
NSLog(@"%@ tag %d",[loadingSprite getChildByTag:111] , [loadingSprite getChildByTag:111].tag)
}
on another class, B.m i write to access method getTag
A *a = [[A alloc] init];
[a getTag];
but unfortunately, the NSLog in getTag shows :
(null) tag 0
how the proper way to access the ccsprite from another class? thanks
Check out my tutorial "Strategies for Accessing Other Cocos2D Nodes In The Scene Hierarchy": http://www.learn-cocos2d.com/2012/09/strategies-accessing-cocos2d-nodes-scene-hierarchy/