// Semi-Singleton: you can access MultiLayerScene only as long as it is the active scene.
static MultiLayerScene* multiLayerSceneInstance;

+(MultiLayerScene*) sharedLayer
{
    NSAssert(multiLayerSceneInstance != nil, @"MultiLayerScene not available!");
    return multiLayerSceneInstance;
}

-(void) dealloc
{
    multiLayerSceneInstance = nil;

    // don't forget to call "super dealloc"
    [super dealloc];
}

与普通的单例不同的是,它不能被初始化

 

使用单例的方法

 

MultiSceneLayer *sceneLayer=[MultiSceneLayer shareLayer];

 

相关文章: