cocos2d::Image* snapshot(float scale){ cocos2d::Size visibleSize = Director::getInstance()->getVisibleSize(); cocos2d::Point visibleOrigin = Director::getInstance()->getVisibleOrigin(); Director::getInstance()->setNextDeltaTimeZero(true); RenderTexture* finalRtx = nullptr; RenderTexture* rtx = RenderTexture::create(visibleSize.wIDth,visibleSize.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8); // rtx->setKeepMatrix(true); cocos2d::Scene* scene = Director::getInstance()->getRunningScene(); cocos2d::Point savedPos = scene->getposition(); scene->setposition(-visibleOrigin); rtx->begin(); // rtx->beginWithClear(0,0); scene->visit(); rtx->end(); scene->setposition(savedPos); if (std::abs(scale - 1.0f) < 1e-6/* no scale */) finalRtx = rtx; else { /* scale */ cocos2d::Rect finalRect = cocos2d::Rect(0,0,visibleSize.wIDth,visibleSize.height); Sprite *sprite = Sprite::createWithTexture(rtx->getSprite()->getTexture(),finalRect); sprite->setAnchorPoint(cocos2d::Point(0,0)); sprite->setFlipY(true); finalRtx = RenderTexture::create(visibleSize.wIDth * scale,visibleSize.height * scale,GL_DEPTH24_STENCIL8); sprite->setScale(scale); // or use finalRtx->setKeepMatrix(true); finalRtx->begin(); // finalRtx->beginWithClear(0,0); sprite->visit(); finalRtx->end(); } Director::getInstance()->getRenderer()->render(); return finalRtx->newImage();}cocos2d::Image* snapshot(Node* startNode,float scale){ // The best snapshot API,support Scene and any Node auto& size = startNode->getContentSize(); // cocos2d::Point visibleOrigin = Director::getInstance()->getVisibleOrigin(); Director::getInstance()->setNextDeltaTimeZero(true); RenderTexture* finalRtx = nullptr; RenderTexture* rtx = RenderTexture::create(size.wIDth,size.height,GL_DEPTH24_STENCIL8); // rtx->setKeepMatrix(true); // cocos2d::Scene* scene = Director::getInstance()->getRunningScene(); cocos2d::Point savedPos = startNode->getposition(); Point anchor; if (!startNode->isIgnoreAnchorPointForposition()) { anchor = startNode->getAnchorPoint(); } startNode->setposition(ccp(size.wIDth * anchor.x,size.height * anchor.y));// startNode->setposition(-visibleOrigin); rtx->begin(); // rtx->beginWithClear(0,0); startNode->visit(); rtx->end(); startNode->setposition(savedPos); if (std::abs(scale - 1.0f) < 1e-6/* no scale */) finalRtx = rtx; else { /* scale */ cocos2d::Rect finalRect = cocos2d::Rect(0,size.wIDth,size.height); Sprite *sprite = Sprite::createWithTexture(rtx->getSprite()->getTexture(),0)); sprite->setFlipY(true); finalRtx = RenderTexture::create(size.wIDth * scale,size.height * scale,0); sprite->visit(); finalRtx->end(); } Director::getInstance()->getRenderer()->render(); return finalRtx->newImage();}总结
以上是内存溢出为你收集整理的cocos2d-x-3.x snapshot全部内容,希望文章能够帮你解决cocos2d-x-3.x snapshot所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)