2016-01-13 36 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