当计数达到零时,我试图进入一个新的场景。我让计数工作下降(3,2,1,0),但我希望场景改为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
答案 0 :(得分: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可能会提供更多详情。