각 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 순서)의 상단에있는 스프라이트 작동하지 않습니다?
이것은 게임 논리를 구현할 때 문제가되는 것 같지만 cocos2d의 제한 사항이 아닙니다. 언제든지 스프라이트를 제거 할 수 있으므로 스프라이트를 특정 순서로 제거 할 필요는 없습니다. 한 번에 여러 개의 스프라이트를 제거해야하는 경우 해당 레이어 또는 노드의 자식 배열을 비워야 모든 레이어를 제거 할 수 있습니다. – LearnCocos2D
@ LearnCocos2D : 스프라이트가 서로 겹칠 때 하나씩, 하나씩 여러 개의 스프라이트를 제거하고 싶지 않습니다. 다른 경우는 태그 순서를 말하는 것입니다. 내가 뭘 하려는지 미안하다. –