cocos2dx-截取屏幕一部分

前端之家收集整理的这篇文章主要介绍了cocos2dx-截取屏幕一部分前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    Image::Format format=Image::Format::PNG;
    auto origin=Director::getInstance()->getVisibleOrigin();
    auto visibleSize=Director::getInstance()->getVisibleSize();
    RenderTexture *renderTexture = RenderTexture::create(visibleSize.width*0.5,visibleSize.height*0.5,Texture2D::PixelFormat::RGBA8888);
    Rect fullRect=Rect(origin.x,origin.y,visibleSize.width*0.5,visibleSize.height*0.5);
    Rect virtualViewPort=Rect(visibleSize.width*0.25,visibleSize.height*0.25,visibleSize.height*0.5);
    //抓取屏幕部分内容保存为纹理。 rtBegin: renderTexture在整个屏幕上的起始位置。 fullRect: 整个屏幕的大小 fullViewport: 整个viewport的大小。
    renderTexture->setVirtualViewport(Point(visibleSize.width*0.25,visibleSize.height*0.25),fullRect,virtualViewPort);
    renderTexture->beginWithClear(0.0f,0.0f,0.0f);
    Director::getInstance()->getRunningScene()->visit();
    renderTexture->end();
    renderTexture->saveToFile("happy.png",format);
原文链接:https://www.f2er.com/cocos2dx/339317.html

猜你在找的Cocos2d-x相关文章