3
當我的玩家與它碰撞時,我怎樣才能讓我的硬幣消失?Sprite Kit - 隱藏SKSpriteNode
我不知道我是否應該使用SKNode,而不是:/。
請幫我似乎無法弄清楚
CODE:
-(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];
}
[硬幣removeFromParent] – LearnCocos2D
不適用於我的任何其他想法? – nickivey
如果您要清除硬幣,它應該消失,只要'硬幣'不是零。如果它不消失,你可能會在同一地點有兩個硬幣。 – LearnCocos2D