views:

180

answers:

1

//prog 1

-(void)gameLogic:(ccTime)dt  
{    
id actionMove = [CCMoveTo actionWithDuration:1.0 position:ccp(windowSize.width/2-400, actualY)];
[actionMove setTag:6];
[self schedule:@selector(update:)];
[hitBullet runAction:actionMove];
}

-(void)update:(ccTime)dt
{
if ( (CGRectIntersectsRect(hitRect, playerRect)) )
  {
   [[[self getActionByTag:6] retain] autorelease];
   [hitBullet stopActionByTag: 6]; 
  }      
}

//prog 2

-(void)gameLogic:(ccTime)dt
{
  id actionMove = [CCMoveTo actionWithDuration:1.0 position:ccp(windowSize.width/2-400, actualY)];
  id hitBulletAction = [CCSequence actionWithDuration:(intervalforEnemyshoot)];
  id hitBulletSeq = [CCSequence actions: hitBulletAction, actionMove, nil];
  [hitBulletSeq setTag:5];
[self schedule:@selector(update:)]; 
  [hitBullet runAction:hitBulletSeq];
}  

-(void)update:(ccTime)dt
{
if ( (CGRectIntersectsRect(hitRect, playerRect)) )
  {
   [[[self getActionByTag:5] retain] autorelease];
   [hitBullet stopActionByTag: 5]; 
  }      
}

While prog1 is working prog2 is not working ? I think the both are same. But why the two stopActions are working differently in two prog1 and prog2 ? I mean the actions are stopped in prog1 but the actions are not stopping in prog2 ? thank You.

A: 

Srikanth, what version of cocos2d are you using?

The answer to your question is no. All actions are treated the same.

The code responsible for removing the action is the following:

// -[CCActionManager removeActionByTag:target:]
-(void) removeActionByTag:(int) aTag target:(id)target
{
    NSAssert( aTag != kActionTagInvalid, @"Invalid tag");
    NSAssert( target != nil, @"Target should be ! nil");

    tHashElement elementTmp;
    elementTmp.target = target;
    tHashElement *element = ccHashSetFind(targets, CC_HASH_INT(target), &elementTmp);

    if( element ) {
        NSUInteger limit = element->actions->num;
        for( NSUInteger i = 0; i < limit; i++) {
            CCAction *a = element->actions->arr[i];

            if( a.tag == aTag && [a originalTarget]==target)
                return [self removeActionAtIndex:i hashElement:element];
        }
//      CCLOG(@"cocos2d: removeActionByTag: Action not found!");
    } else {
//      CCLOG(@"cocos2d: removeActionByTag: Target not found!");
    }
}

What I would recommend you do is turn on Cocos2d debugging, and un-comment those two CCLog lines. That should tell you if there's a problem in there.

If that doesn't tell you anything, it may be of interest to look into the CCSequence class. Perhaps, if the sequence is being removed, it doesn't remove the actions IN the sequence itself?

All actions are treated equal, but perhaps this Sequence action should be an exception to that.

nash
Nash,I am using cocos2d_0.99.0 version. Is there any wrong in my code ?But, in Prog1 the action is stopping and in prog2 it is not stopping. So I tried [self removeChildByTag: cleanUp: ]; It is working. But, why not removeActionByTag: . I would do what you have said and debug it.Thank You.
srikanth rongali