2016-01-13 73 views
1

我一直在这个问题上停留了一天,现在我一直在搜索论坛以及尝试自己修复。SpriteKit节点在启动后晚上渲染到场景中

我的问题在于在游戏启动时将一些SKSpriteNodes添加到背景顶部的场景中。问题是它的随机!有时候SpriteNodes在其他时候可见,而我不知道为什么。我已经注册了并且注意了节点数量,我的所有SpriteNodes都加载到了场景中,但是它们的可见性问题是一个硬币折腾!有时我可以看到他们中的两个,有时我只能看到他们中的一个,有时甚至都看不到。 我包括我使用,使SpriteNodes方法:

- (void) setupMenuButtons 
{ 
    //initialize storyButton texture,size,and position 
    SKTexture *storyButtonTexture = [SKTexture textureWithImageNamed:@"storybutton"]; 
    storyButton = [SKSpriteNode spriteNodeWithTexture:storyButtonTexture size:CGSizeMake(self.frame.size.width/2.84, 
                         self.frame.size.height/4.26)]; 
    storyButton.position = CGPointMake(self.frame.size.width - (storyButton.size.width/2),self.frame.size.height/1.25); 
    [menuLayer addChild:storyButton]; 
    NSLog(@"Added story"); 
    //initialize creditsButton texture,size,and position 
    SKTexture *creditsButtonTexture = [SKTexture textureWithImageNamed:@"creditsbutton"]; 
    creditsButton = [SKSpriteNode spriteNodeWithTexture:creditsButtonTexture size:CGSizeMake(self.frame.size.width/2.84, 
                          self.frame.size.height/4.26)]; 
    creditsButton.position = CGPointMake(self.frame.size.width - (creditsButton.size.width/2),self.frame.size.height/2); 
    [menuLayer addChild:creditsButton]; 
    NSLog(@"Added credits"); 
    //initialize usicButton texture,size,and position 
    SKTexture *musicButtonTexture = [SKTexture textureWithImageNamed:@"musicbuttonOFF"]; 
    musicButton = [SKSpriteNode spriteNodeWithTexture:musicButtonTexture size:CGSizeMake(self.frame.size.width/2.84, 
                         self.frame.size.height/9.84)]; 
    musicButton.position = CGPointMake(self.frame.size.width - (musicButton.size.width/2),self.frame.size.height/3.45); 

    [menuLayer addChild:musicButton]; 
     NSLog(@"Added music"); 
} 

和inwhich我暂停和恢复我的游戏方法:

- (void)pauseGame 
{ 
    self.scene.paused = YES; 
    backgroundLayer.paused = YES; 
    menuLayer.paused = YES; 
    [player pause]; 
    isPaused = YES; 
    NSLog(@"paused"); 
} 

- (void)resumeGame 
{ 
    backgroundLayer.paused = NO; 
    menuLayer.paused = NO; 
    [player play]; 
    isPaused = NO; 
    NSLog(@"resumed"); 
} 

回答

0

一种方法来解决你的问题是指定所有精灵的zPosition。只需添加这些行:

background.zPosition = 0.0; 
storyButton.zPosition = 10.0; 
creditsButton.zPosition = 10.0; 
musicButton.zPosition = 10.0; 

另一种方式是将背景与0.0 zPosition和所有的按钮添加到SKNode到另一个节点与10.0 zPosition(我想你差点没)..你能否错过这两行?

backgroundLayer.zPosition = 0.0; 
menuLayer.zPosition = 10.0; 

我希望这可以帮助你。 :)

+0

非常感谢你!!!!!!! –

+0

非常欢迎!当我的回答很有用时,我很乐意提供帮助,并更高兴。 :)祝你好运! – RoberRM