2014-02-14 57 views
0

當計數達到零時,我試圖進入新場景。我有計數工作下降(3,2,1,0),但我想現場改變在0當計數達到0時更改場景Cocos2d 3.0

我將如何能夠實現這一目標?

代碼控制是放置在現場的計數標籤(去是我使用的得分INT)

gone=3; 
gonelabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Left: %d",gone] fontName:@"a2203.ttf" fontSize:18.0f]; 
gonelabel.positionType = CCPositionTypeNormalized; 
gonelabel.color = [CCColor blackColor]; 
gonelabel.position = ccp(0.15f, 0.95f); // Top Right of screen 
[self addChild:gonelabel]; 

代碼計數的碰撞

- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair monsterCollision:(CCNode *)monster barrierCollision:(CCNode *)barrier { 

[monster removeFromParent]; 

gone--; 
[gonelabel setString:[NSString stringWithFormat:@"Left: %d",gone]]; 

return YES; 
} 

謝謝你的任何忠告:d

回答

1

假設你有一個代表你希望切換到的場景的類(例如YourNewScene),請在代碼中添加如下代碼:

- (void) switchScene 
{ 
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[YourNewScene scene]]]; 
} 

- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair monsterCollision:(CCNode *)monster barrierCollision:(CCNode *)barrier 
{ 
    [monster removeFromParent]; 
    gone--; 
    [gonelabel setString:[NSString stringWithFormat:@"Left: %d",gone]]; 

    if(gone == 0) 
     [self switchScene]; 

    return YES; 
} 

This question可能提供更多細節。

+0

工作完美無瑕,謝謝 – Crazycriss