0

各スプライトの上にあるが 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 オーダーを持つ) スプライトに対して が機能しないのはなぜですか?

4

1 に答える 1

1

より良い方法があるかどうかはわかりませんが、頭に浮かぶのは、レイヤーの子とその z オーダーを確認し、z オーダーに基づいて削除することです。

于 2012-01-26T12:00:06.677 に答える