Cocos2D iPhone - 删除CCTransition之间的黑屏

时间:2012-02-22 05:26:11

标签: iphone ios cocos2d-iphone

我在我的应用上使用cocos2d。我正在使用

转换到另一个场景
[[CCDirector sharedDirector] replaceScene: 
 [CCTransitionFadeDown transitionWithDuration:0.5f scene:otherScene]];

在另一个场景的init部分,正在使用CCMenu构建一个菜单。这是一个全屏菜单。

我的问题是:转换发生在黑屏,然后出现菜单。换句话说,转换是在菜单渲染之前完成的,因此,我看到一个丑陋的黑色屏幕0.5秒,然后,在转换完成后,我看到菜单。

为了清楚地说明,第一个场景有一张船的照片,第二个场景是汽车的照片。我现在拥有的是船转向黑色然后汽车弹出。我需要船过渡到汽车。

我该怎么做?感谢。

注意:我找到this guy with the same problem,但我尝试了解决方案但没有成功。

2 个答案:

答案 0 :(得分:2)

如果你还没有使用它,这值得一试;它可以在场景加载过程中消除黑色闪烁。在切换场景之前运行以下方法,以防它影响您的问题(取消注释这些行并直接调用方法):

- (void) removeStartupFlicker
{
    //
    // THIS CODE REMOVES THE STARTUP FLICKER
    //
    // Uncomment the following code if you Application only supports landscape mode
    //

    //  CC_ENABLE_DEFAULT_GL_STATES();
    //  CCDirector *director = [CCDirector sharedDirector];
    //  CGSize size = [director winSize];
    //  CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"];
    //  sprite.position = ccp(size.width/2, size.height/2);
    //  sprite.rotation = -90;
    //  [sprite visit];
    //  [[director openGLView] swapBuffers];
    //  CC_ENABLE_DEFAULT_GL_STATES();

}

答案 1 :(得分:1)

我已经在我的菜单中实现了转换(同样的问题),通过在init中的所有内容上添加黑色图层来调用它为'fadeInView',不透明度为255,并且在onEnter中我运行一个动作来淡化不透明度为0.如下:

-(id) init {
    self=[super init];
    if(self){
        // do your stuff
        blackShroudLayer_=[CCLayerColor layerWithColor:ccc4(0, 0, 0, 255) width:K_SCREEN_WIDTH height:K_SCREEN_HEIGHT];
        [self addChild:blackShroudLayer_ z:500];
    }  
    return self;
}

-(void) onEnter{

    // need to [super onEnter] first to that we are running 

    [super onEnter];
    id sh = [CCFadeTo actionWithDuration:K_FADE_TIME opacity:0];
    id seq = [CCSequence actions:sh,[CCCallFunc actionWithTarget:self selector:@selector(onUnshroudComplete)], nil];
    [blackShroudLayer_ runAction:seq];
}

-(void) onUnshroudComplete{
     [blackShroudLayer_ removeFromParentAndCleanup:YES];
}

常量和blackShroudLayer_在类.h文件中定义。