改变场景cocos2d

时间:2014-03-28 23:36:48

标签: ios objective-c cocos2d-iphone

我试图从gamePlayscene更改为GameOverScene,但是当模拟器尝试更改场景时,模拟器会停止,但我不会在日志中收到任何消息。

GameOverScene.h

@interface GameOverScene : CCScene {
    GameOverScene *scene;
    //screen size
    float winWidth;
    float winHeight;

    //Game vars
    int score;

    //Facebook vars
    FBSession* session;
    NSString *messageStr;
    NSString *userid;    
}

+ (GameOverScene *)scene;
- (id)init;

@end

GameOverScene.m

@implementation GameOverScene {


}


+ (GameOverScene *)scene
{


    return [[self alloc] init];


}

// -----------------------------------------------------------------------

- (id)init
{
    if( (self=[super init] )) {
        NSLog(@"define tamanho da tela");
        winWidth = self.contentSize.width;
        winHeight = self.contentSize.height;



        NSLog(@"define botao");
        // Facebook login button
        CCButton *fbLoginButton = [CCButton buttonWithTitle:@"Login with FB" fontName:@"Verdana-Bold" fontSize:30.0f];
        fbLoginButton.position = ccp(winWidth/2, winHeight/2);
        [fbLoginButton setTarget:self selector:@selector(fbLoginClicked:)];
        [self addChild:fbLoginButton];

    }

}

我以这种方式调用GameOverScene:

 [[CCDirector sharedDirector] replaceScene:[GameOverScene scene]
                               withTransition:[CCTransition transitionFadeWithDuration:1.0f]];

1 个答案:

答案 0 :(得分:2)

put"返回自我"在if块之后的 - (id)init方法中。