如何删除位于每个精灵之上但具有不同 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 顺序)?