刷新cocos2d中的游戏场景

时间:2014-02-05 11:21:24

标签: cocos2d-iphone

嘿伙计们,我正在努力解决以下问题。我得到2层,一层用于控制,另一层用于游戏。问题是当我从控制层中重新启动一个函数重启时,游戏被卡住了(游戏的场景被刷新并显示但是它已失控)。不知道问题出在哪里。

//restart function from input layer

......

-(id) init
{
    if ((self = [super init]))
    {......}
    return self;
}

......

-(void)restart
{
    GameScene* game = [GameScene sharedGameScene];
    [game restartScene];
}

//gameLayer

......

static GameScene* instanceOfGameScene;

@implementation GameScene

+(GameScene*) sharedGameScene
{
    if(instanceOfGameScene == nil)
        instanceOfGameScene = [[self alloc]init];
    return instanceOfGameScene;
}

+(id) scene
{   
    CCScene* scene = [CCScene node];
    GameScene* layer = [GameScene node];
    [scene addChild:layer z:0];

    InputLayer* inputLayer = [InputLayer node];
    [scene addChild:inputLayer z:1];
    return scene;
}

-(void) restartScene
{
    CCScene * newScene = [GameScene scene];
    [[CCDirector sharedDirector] replaceScene:\
                 [CCTransitionFade transitionWithDuration:0.7f scene:newScene]];
}

......

1 个答案:

答案 0 :(得分:0)

[scene:newScene]似乎不是有效的ObjC语法,这甚至可以编译吗?

无论如何,你要在那里使用newScene而不是其他:

-(void) restartScene
{
    CCScene * newScene = [GameScene scene];
    [[CCDirector sharedDirector] replaceScene:newScene];
}