从cocos2d中的另一个图层重新启动场景

时间:2014-02-05 12:18:34

标签: 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]];
}

...

0 个答案:

没有答案