gpt4 book ai didi

ios - Sprite Kit - 隐藏 SKSpriteNode

转载 作者:可可西里 更新时间:2023-11-01 06:23:12 26 4
gpt4 key购买 nike

如何让我的硬币在我的玩家碰撞时消失?

我不知道我是否应该使用 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];
}

最佳答案

首先获取币节点。它可以是 contact.bodyA.node 或 contact.bodyB.node。例如:-

SKNode* coinNode = contact.bodyA.node;
[coinNode removeFromParent]; //This should work

如果你只想隐藏节点,那么使用

coinNode.hidden = YES;

关于ios - Sprite Kit - 隐藏 SKSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22082676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com