精灵套件 - 隐藏SKSpriteNode

nic*_*vey 3 objective-c ios sprite-kit

当我的玩家与它碰撞时,如何让我的硬币消失?

我不知道我应该使用SKNode代替什么:/.

请帮助我似乎无法弄明白

码:

 -(void)spawnCoin {

SKNode* coinNode = [SKNode node];
coinNode.position = CGPointMake(self.frame.size.width + _buildTexture1.size.width + 150 + (arc4random() % 100), 0 );
coinNode.zPosition = -10;

CGFloat y = arc4random() % (NSInteger)( self.frame.size.height / 2 ) + 40;

SKAction* spin = [SKAction repeatActionForever:[SKAction animateWithTextures:@[ _coinTexture1, _coinTexture2, _coinTexture3, _coinTexture4, _coinTexture5, _coinTexture6, _coinTexture7, _coinTexture8, _coinTexture9, _coinTexture10] timePerFrame:0.05]];
coin = [SKSpriteNode spriteNodeWithTexture:_coinTexture10];
[coin runAction:spin];


[coin setScale:1];
coin.position = CGPointMake( 0, y );
coin.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:coin.size];
coin.physicsBody.dynamic = NO;
coin.physicsBody.categoryBitMask = coinCategory;
coin.physicsBody.contactTestBitMask = playerCategory;
[coinNode addChild:coin];
[coinNode runAction:_moveCoinAndRemove];
[_coins addChild:coinNode];


}

 - (void)didBeginContact:(SKPhysicsContact *)contact {
if( _moving.speed > 0 ) {
    if( ( contact.bodyA.categoryBitMask & coinCategory ) == coinCategory || ( contact.bodyB.categoryBitMask & coinCategory ) == coinCategory ) {

         //I have Tried  [coin removeAllChildren];


        _score++;
        _scoreLabelNode.text = [NSString stringWithFormat:@"%ld", (long)_score];
 }
Run Code Online (Sandbox Code Playgroud)

Sri*_*nth 9

首先得到硬币节点.它可以是contact.bodyA.node或contact.bodyB.node.例如:-

SKNode* coinNode = contact.bodyA.node;
[coinNode removeFromParent];  //This should work
Run Code Online (Sandbox Code Playgroud)

如果您只想隐藏节点,请使用

coinNode.hidden = YES;
Run Code Online (Sandbox Code Playgroud)