cocos2d屏幕反色

人物死亡时要屏幕反色处理


void    GameLayer::initPlayerDead()
{
    state = G_STATE_DEAD_PAUSE;
    
    CCLayerColor* layer = CCLayerColor::layerWithColor( ccc4(255, 255, 255, 0) );
    layer -> setTag(GAME_PLAY_DEAD_LAYER_TAG);
    addChild(layer);
    
    schedule(schedule_selector(GameLayer::updatePlayerDead), 0.1f);
    schedule(schedule_selector(GameLayer::endUpdatePlayerDead), 1.0f);
}

void   GameLayer::updatePlayerDead(cocos2d::ccTime dt)
{
    
    CCLayerColor *layer = (CCLayerColor*)getChildByTag(GAME_PLAY_DEAD_LAYER_TAG);
    
    GLenum src;
    GLenum dst;
    
	if( layer->getBlendFunc().dst == GL_ZERO )
    {
        src = CC_BLEND_SRC;
        dst = CC_BLEND_DST;
    }
	else
    {
        src = GL_ONE_MINUS_DST_COLOR;
        dst = GL_ZERO;
    }
    
    ccBlendFunc bf = {src, dst};
    layer->setBlendFunc( bf );

}

void   GameLayer::endUpdatePlayerDead(cocos2d::ccTime dt)
{
    state =  G_STATE_JUMP;
    
    CCLayerColor *layer = (CCLayerColor*)getChildByTag(GAME_PLAY_DEAD_LAYER_TAG);
    if (layer != NULL) {
        layer -> removeFromParentAndCleanup(true);
    }
    
    unschedule(schedule_selector(GameLayer::updatePlayerDead));
    unschedule(schedule_selector(GameLayer::endUpdatePlayerDead));
}


你可能感兴趣的:(cocos2d)