[cocos2d-iphone]跳帧

今天写一个小游戏的时候 在触发结束的时候 因为在结束方法里调用了 

截图 导致了 出现跳帧。

思考了一下。

cocos2d-iphone是使用时序队列的而不是多线程。

那么就意味着 我这个结束方法(stop)执行的时间越长,就会导致在cocos2d的时序队列的下一个刷新帧执行间隔时间变长。从而出现跳帧。

思路:减少stop方法的执行时间。(但是 截图必须在菜单出来前截图。so 必须由stop来启动截图。)

那么这里解决方法是使用[self performSelector:@selector(shotImage) withObject:nil afterDelay:0.2];

从而减少stop方法的执行时间。

-(void)stop{

    [self unscheduleAllSelectors];

    for(CCSprite* sp in [self children]){

        if([sp isKindOfClass:[CCSprite class]]){

            [sp stopAllActions];

        }

    }

    if(scroe>[UserDefault highScore]){

        [UserDefault setHighScore:scroe];

        [self performSelector:@selector(shotImage) withObject:nil afterDelay:0.2];

    }else{

        menuRestart.visible=YES;

    }

 

 

 

//    [self performSelector:@selector(resetValue) withObject:nil afterDelay:1];

}

 

-(void)shotImage{

    [CCDirector sharedDirector].nextDeltaTimeZero = YES;

    CGSize winSize = [CCDirector sharedDirector].winSize;

    CCLayerColor* whitePage = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height];

    whitePage.position = ccp(winSize.width/2, winSize.height/2);

    CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];

    [rtx begin];

    [whitePage visit];

    [[[CCDirector sharedDirector] runningScene] visit];

    [rtx end];

    UIImage* image=[rtx getUIImage];

    [UserDefault setHighImage:image];

    menuRestart.visible=YES;

 

}

猜你喜欢

转载自poolo.iteye.com/blog/1853828