2012-01-26 3 views
0

각 z 위에 다른 스프레이를 제거하려면 어떻게해야합니까? 내가 사용애니메이션, 다른 z 순서로 스프라이트 제거

코드는 다음과 같습니다

- (void)removeSelectedSprite:(CGPoint)touchLocation { 
    CCSprite * newSprite = nil; 
    for (CCSprite *sprite in selectedSpritesArray) { 
     if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {    
      newSprite = sprite; 
      break; 
     } 
    } 
    if (newSprite) { 

     CCSprite *fixedSprite = [CCSprite spriteWithSpriteFrameName:@"Animation_01.png"]; 

     fixedSprite.position = ccp(newSprite.contentSize.width/2,newSprite.contentSize.height/2); 
     [newSprite addChild:fixedSprite]; 

     NSMutableArray *animFrames = [NSMutableArray array]; 
     for(int i = 1; i <= 5; ++i) { 

      [animFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"Animation_%02d.png", i]]]; 
     } 

     CCAnimation *anim = [CCAnimation animationWithFrames:animFrames delay:0.05f]; 
     CCActionInterval *animAction = [CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO]; 

     id seq = [CCSequence actions: animAction, [CCCallFunc actionWithTarget:fixedSprite selector:@selector(removeFromParentAndCleanup:)], [CCCallFunc actionWithTarget:newSprite selector:@selector(removeFromParentAndCleanup:)], nil]; 
     [fixedSprite runAction:seq]; 
    } 

} 

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {  
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; 
    [self removeSelectedSprite:touchLocation];  
    return TRUE;  
} 

이유는 각각 (가진 다른 Z 순서)의 상단에있는 스프라이트 작동하지 않습니다?

+0

이것은 게임 논리를 구현할 때 문제가되는 것 같지만 cocos2d의 제한 사항이 아닙니다. 언제든지 스프라이트를 제거 할 수 있으므로 스프라이트를 특정 순서로 제거 할 필요는 없습니다. 한 번에 여러 개의 스프라이트를 제거해야하는 경우 해당 레이어 또는 노드의 자식 배열을 비워야 모든 레이어를 제거 할 수 있습니다. – LearnCocos2D

+0

@ LearnCocos2D : 스프라이트가 서로 겹칠 때 하나씩, 하나씩 여러 개의 스프라이트를 제거하고 싶지 않습니다. 다른 경우는 태그 순서를 말하는 것입니다. 내가 뭘 하려는지 미안하다. –

답변

0

더 좋은 방법이 있는지 모르겠지만 마음에 떠오르는 것은 레이어 하위 항목과 해당 z 순서를 확인하고 z 순서에 따라 제거하는 것입니다.

+0

나는 [Ray 's example] (http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d)을 생각해 냈다. 하지만 여전히 문제가 있습니다. 모든 객체가 선택된 객체에서 제거되지는 않습니다. NSMutableArray; 어쩌면 당신은 지금 ... –

관련 문제