SKEmitterNode在所有其他节点后面呈现

时间:2015-10-28 23:34:25

标签: objective-c xcode sprite-kit

我有一个我似乎无法解决的问题。 这是我的设置:

SKScene
->Background
->WorldNode
-->Character
-->Platforms
-->Smoke (SKEmitterNode)

我基本上希望烟雾跟随角色,同时留下痕迹。

这是我在didMoveToView方法中使用的代码:

[self addChild:[SKSpriteNode spriteNodeWithImageNamed:@"background.png"]];
[self addChild:[self worldNode]];
[worldNode addChild:[self firstPlatform]];
character = [Character createNewCharacterAtPosition:[self firstPlatform]];
[worldNode addChild:character];
NString *smokePath = [[NSBundle mainBundle] pathForResource:@"smokeParticle" ofType:@"sks"];
smoke = [NSKeyedUnarchiver unarchiveObjectWithFile:smokePath];
smoke.position = character.position;
smoke.zPosition = 100; // no matter what value i put here it doesn't get affected
[smoke setTargetNode:worldNode];
[worldNode addChild:smoke];

在更新方法中,我使用以下内容使烟雾跟随角色:

smoke.position = player.position;

现在,如果我删除[smoke setTargetNode:worldNode],烟雾应该在哪里(在角色后面和背景前面),但是烟雾随着角色一起移动,并没有产生所需的尾迹效果。 / p>

我尝试设置[scene.view setIgnoresSiblingOrder:YES],但它没有解决问题。

感谢任何帮助。

干杯。

1 个答案:

答案 0 :(得分:0)

不要更新SKEmiteNode位置,只需将SKEmiteNode添加到角色,然后通过设置发射器targetNode属性来定义将在哪个节点中发射粒子。

world更改为发射粒子发射粒子的背景或场景

smoke.targetNode = world

另外,通过定义此SKEmiteNode将留下痕迹