2013-02-12 91 views
0

我已經實現了一款遊戲,在遊戲結束時,遊戲結束。 因此,我必須暫停此時的場景,然後我必須實現遊戲結束(完成)標籤,點和允許重新啓動遊戲的按鈕。現在,當遊戲結束時,我已經在標籤和新開始的遊戲中覆蓋了遊戲!我想在遊戲結束和分數的視圖中暫停遊戲。遊戲結束並重新啓動按鈕Cocos2d

這是我的代碼:

-(void)gameOver:(int)value punteggio:(id)punti{ 
    if (value == 1) { 
     // partita vinta 
    } else if (value == 2) { 
     if (life > 1) { // 1 
      life = life - 1; 
      for (CCSprite *spr in spriteLifeArray) { 
       if (life == spr.tag) { 
        [self removeChild:spr cleanup:YES]; 
       } 
      } 
     } else { 
      // partita persa 
      Gameover = [CCLabelTTF labelWithString:@"Game Over!" fontName:@"Marker Felt" fontSize:34]; 
      [Gameover setColor:ccc3(255, 1, 1)]; 
      Gameover.position = ccp(size.width/2, size.height/2); 
      [self addChild:Gameover]; 
      //blinking 
      id action1 = [CCBlink actionWithDuration:0.3 blinks:5]; 
      [Gameover runAction: action1]; 
      [[CCDirector sharedDirector] pause]; 
     } 
    } 
} 

我該如何解決?我怎樣才能讓這個按鈕在暫停的場景中重新開始遊戲? 謝謝

回答

1

我已經解決了創建一個節點,稱爲GameOVer與函數重新啓動。在GAMEOVER實現我所著的功能重新啓動

-(void) restart {  
    [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]]; 
} 

和我聯繫這個功能在GAMEOVER層標籤:

CCMenuItemLabel *back = [CCMenuItemLabel itemWithLabel:label2 target:self selector:@selector(restart)]; 

最後我連在主層,如果lives==0此代碼

[[CCDirector sharedDirector] replaceScene:[GameOver node]]; 

而且一切正常! :)

1

你可以做這樣的:

創建一個CCMenuItemLabel簡單CCMenu。

 CCMenuItemLabel *gameOver = [CCMenuItemLabel itemWithLabel:@"Game Over!" target:self selector:@selector(restart:)]; 
     CCMenu *menu = [CCMenu menuWithItems:gameOver, nil]; 
     [self addChild:menu z:(Something bigger than all others so that it shows up on top)]; 

然後在您重啓方法:

-(void) restart:(id)sender{ 
      menu.visible = NO; 
      //code to restart your game; 
    } 

希望這有助於。

+0

謝謝...更大的手段,例如與屏幕大小的background.png?我可以將我的代碼發送給您,詳細說明它的工作原理嗎?感謝您的幫助! :) – TheInterestedOne 2013-02-13 17:03:40

+0

當你將一個孩子添加到自己時,z是孩子被繪製的順序(即z:0的孩子被繪製在z:5的孩子的後面),所以你希望z爲你遊戲結束標籤比所有其他都大,因此它被繪製在頂部。 – bluestunt 2013-02-13 21:08:35

+0

我會很高興看到你的代碼。 – bluestunt 2013-02-13 21:09:27

相關問題