I have an action that I declared in the -init method.
-(id) init
{
if( (self=[super init])) {
sprite = [CCSprite spriteWithFile:@"Icon@2x.png"];
sprite.position = ccp(150,150);
[self addChild:sprite];
sprite.tag = 13;
self.isTouchEnabled = YES;
CCAction *anAction = [CCBlink actionWithDuration:5 blinks:10];
anAction.tag = 15;
}
return self;
}
Now, I can access the sprite without any problems.
-(void)ccTouchesBegan:(NSSet *)touch withEvent:(UIEvent *)event {
CCNode *node = [self getChildByTag:13];
NSAssert([node isKindOfClass:[CCSprite class]],@"is NOT member of CCSprite");
CCSprite *sprite = (CCSprite *)node;
sprite.scale = CCRANDOM_0_1();
}
Now I don’t know how to access my action via tag.. would anyone mind showing me a small example ?
Your code assignes a new action to an automatic variable and doesn’t run it.
anActionis not retained by anyone, so it gets autoreleased:If you schedule your action with
[self runAction:anAction], you can access it by[sprite getActionByTag:15]. But if you want to create an action without running it, you should save your action in your class property and access it by casting a node to your class.