Question

Im trying to get to a new scene when the count reaches to zero. I have the count working going down ( 3, 2, 1, 0) but I want the scene to change at 0

How would i be able to achieve this?

Code controlling the label that places the count on the scene (gone is the int i use for score)

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];

Code counting the collisions

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

[monster removeFromParent];

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

return YES;
}

Thank you for any advice :D

Was it helpful?

Solution

Assuming you've got a class representing a scene you wish to switch to (ex. YourNewScene), add something like this to your code:

- (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 may provide more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top