0

touchesBegan メソッドにパーティクル エフェクトを追加しようとしているので、ユーザーが描画されたスプライト (SKSpriteNode) に触れると、パーティクル エフェクトが描画されます。ただし、Attempted to add a SKNode that already has a parent: SKEmitterNodeというエラーが表示されます。いくつかのコンテキストを追加するには... ゲームは、ブロック (deleteNode) が隣接する色に基づいて削除される宝石をちりばめた/キャンディ クラッシュ スタイルです。タッチ イベントでは、再帰的に反復し、隣接するブロックをチェックして配列に追加し、後で削除します。各ブロック (deleteNode) が削除される前に、パーティクル イベントを発生させたいと思います。どちらも SKNode を継承しているため (右?)、競合がわかりません...

@interface
{
   NSString *blockParticlePath;
   SKEmitterNode *blockParticle;
}

初期化メソッドで...

blockParticlePath = [[NSBundle mainBundle] pathForResource:@"blockParticle" ofType:@"sks";
blockParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:blockParticlePath];

in touches始まりました...

blockParticle.position = deleteNode.position;
blockParticle.particleColor = deleteNode.color;
[self addChild:blockParticle];

私が頭がおかしくないことを確認するために、他のフォーラムをチェックして、シーンにパーティクル エフェクトを追加するための同じロジックを見てきました。前もって感謝します。さらに情報が必要な場合はお知らせください。

4

1 に答える 1

0

@whfissler、あなたの説明は、この解決策を特定するのに大いに役立ちました。

このエラーは、多くの SKSpriteNodes がアクティブな場合 (バロン ゲーム) にのみ発生しました。バルーンをクリックするたびにポップし、SKEMitterNode (爆発) が追加されます。爆発によって作成された粒子が互いに接触すると、あなたと同じエラーが発生するようです。コードを次から変更しました。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    SKEmitterNode *explosion = [SKEmitterNode orb_emitterNamed:@"ballonEksplosion"];
    CGPoint positionInScene = [touch locationInNode:self];
    explosion.position = positionInScene;
    SKSpriteNode *touchedSprite;
    for ( int i = 0; i < [[self nodesAtPoint:positionInScene] count]; i++)
    {
        touchedSprite = (SKSpriteNode *)[[self nodesAtPoint:positionInScene] objectAtIndex:i];
        if ([touchedSprite.name isEqualToString:@"BALLON"])
        {


            [(MBDBallon *)touchedSprite popAndRemoveWithSoundEffect];
            [self addChild:explosion];
        }
    }
}

に:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    SKSpriteNode *touchedSprite;
    for ( int i = 0; i < [[self nodesAtPoint:positionInScene] count]; i++)
    {
        touchedSprite = (SKSpriteNode *)[[self nodesAtPoint:positionInScene] objectAtIndex:i];
        if ([touchedSprite.name isEqualToString:@"BALLON"])
        {
            SKEmitterNode *explosion = [SKEmitterNode orb_emitterNamed:@"ballonEksplosion"];
            explosion.position = positionInScene;
            [(MBDBallon *)touchedSprite popAndRemoveWithSoundEffect];
            [self addChild:explosion];
        }
    }
}

そしてそれはうまくいきました。私には、私の爆発 SKEmitterNode が SKScene で何らかの形で長く保持されていたため、 currentPosition に別の SKEmitterNode を追加すると、次の問題が発生するようです。

self nodesAtPoint:positionInScene

nodesAtPoint スタック。

私はそれを完全には理解していません。

于 2014-04-18T09:53:44.527 に答える