儿童精灵出现在父母之下

时间:2014-07-23 18:12:20

标签: objective-c xcode sprite-kit

我只是想在“宇宙飞船”上添加精灵“光”。因此,你可以在下面看到我作为太空船的孩子增加了光线,然而,光线出现在宇宙飞船的下方,如下图所示。任何人都可以告诉我为什么会发生这种情况,我该如何解决?

- (void)newSpaceshipAtLocation:(CGPoint)location{
SKSpriteNode *hull = [[SKSpriteNode alloc]initWithImageNamed:@"Spaceship"];

hull.position = location;
hull.name = @"Spaceship";
hull.scale = 0.5;

SKSpriteNode *light = [self lights];
light.position = CGPointMake(hull.size.width / 5.0, hull.size.height/5.0);
[hull addChild:light];

[self addChild:hull];
}

- (SKSpriteNode *)lights{
SKSpriteNode *light = [[SKSpriteNode alloc]initWithColor:[NSColor yellowColor] size:CGSizeMake(50.0, 50.0)];

SKAction *blink = [SKAction sequence:@[
                                       [SKAction fadeOutWithDuration:0.5],
                                       [SKAction fadeInWithDuration:0.5],
                                       ]];
[light runAction:[SKAction repeatActionForever:blink]];
light.name = @"light";

return light;
}

Yellow light under the spaceship

1 个答案:

答案 0 :(得分:1)

尝试在zPosition上设置light属性。如果你将它设置为高于hull精灵的任何值,它应该可以工作。