2010-04-13 29 views
0

// PROG 1做[sprite stopActionByTag:kTag]; CCAction和CCSequence的工作方式不同嗎?

-(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]; 
    }  
} 

雖然PROG1工作PROG2不工作?我認爲兩者都是一樣的。但爲什麼兩個stopActions在兩個prog1和prog2中的工作方式不同?我的意思是行動在prog1停止,但行動不是在prog2停止? 謝謝你。

回答

0

Srikanth,你使用的是什麼版本的cocos2d?

你的問題的答案是否定的。所有的行爲都是一樣的。

的負責清除行動代碼如下:

// -[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!"); 
    } 
} 

我會建議你要做的就是打開cocos2d的調試,並取消註釋這兩個CCLOG線。這應該告訴你是否有問題。

如果這沒有告訴你任何事情,那麼查看CCSequence類可能很有用。也許,如果序列被刪除,它不會刪除序列本身中的動作?

所有的動作都是平等的,但是這個動作應該是一個例外。

+0

Nash, 我正在使用cocos2d_0.99.0版本。在我的代碼中是否有任何錯誤?但是,在Prog1中,操作正在停止,並且在prog2中它不會停止。所以我試過 [self removeChildByTag:cleanUp:];這是工作。但是,爲什麼不removeActionByTag:。我會做你說的並且調試它。 謝謝。 – 2010-04-13 12:59:20

相關問題