Below sample code never come out of while loop and its printing the number of running actions as 1 always. What I am missing?
Thanks in advance Krishna
-(id)init
{
if(self == [super init])
{
CCSPrite *mySprt = [CCSprite spriteWithFile:@"myFile.png"];
mySprt.position = ccp(160,240);
mySprt.tag = 331;
CCFadeTo *fadeSprt = [CCFadeTo actionWithDuration:20.0 opacity:0];
[mySprt runAction:fadeSprt];
[self addChild:mySprt];
[self checkActionCount];
}
return self;
}
-(void)checkActionCount
{
while([self getchildByTag:331].numberofrunningactions > 0)
{
NSLog(@"Number of actions = %d",[self getchildByTag:331].numberofrunningactions);
continue;
}
NSLog(@"Number of actions = %d",[self getchildByTag:331].numberofrunningactions);
}
You have an endless loop:
The
continuestatement will exit the current block to re-evaluate thewhilecondition, which is true, which will do acontinue, and re-evaluate thewhilecondition, and so on for all eternity.Instead try this:
and call the
checkActionCountmethod from a scheduled selector, for instaceupdate:, so that the condition is evaluated once every frame.