cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法

cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法,第1张

概述function WeixinShareTips.createWeixinImageFile(bShareCurrentScene, func_next) local imgSize = cc.size(640, 960) local backGround = { path = "weixin/background_twoDimension.jpg",
function WeixinShareTips.createWeixinImagefile(bShareCurrentScene,func_next)    local imgSize = cc.size(640,960)    local backGround = {        path = "weixin/background_twoDimension.jpg",pos = cc.p(imgSize.wIDth / 2,imgSize.height / 2),scale = 1    }    local logo = {        path = cc.logos[cc.getSDKPlat()],pos = cc.p(503,848),scale = 0.51    }    local twoDimension = {        path = nil,pos = cc.p(532,106),scale = 1    }    if bShareCurrentScene then        backGround = nil        logo.pos = cc.p(117,550)        twoDimension = nil        imgSize = cc.size(960,640)        logo.scale = 0.3    elseif cc.getSDKPlat() == "ios_yd" then        twoDimension.path = "weixin/twoDimension_bIErangwomaoxian.jpg"    elseif cc.getSDKPlat() == "ios_yd2" then        twoDimension.path = "weixin/twoDimension_maoxianqishituan.jpg"    elseif cc.getSDKPlat() == "ios_yd3" then        twoDimension.path = "weixin/twoDimension_menghuanqishituan.jpg"    else        backGround.path = "weixin/background_noDimension.jpg"        twoDimension = nil    end    local bigImagePath = WeixinShareTips.createWeixinImagefileWithlogoAndTwoDimension("bigWeixinShare.jpg",backGround,logo,twoDimension,imgSize)    local saveRet = bigImagePath ~= nil    local function delayDoSomething(call_todo)        cc.Director : getInstance() : getRunningScene()  : runAction(cc.Sequence:create(        cc.DelayTime:create(0.1),cc.CallFunc:create(function ()            call_todo()        end)))    end    delayDoSomething(function()        local imgScale = 1/8        imgSize = cc.size(imgSize.wIDth * imgScale,imgSize.height * imgScale)        backGround = {            path = bigImagePath,scale = imgScale        }        local smallimagePath = WeixinShareTips.createWeixinImagefileWithlogoAndTwoDimension("smallWeixinShare.jpg",nil,imgSize)        delayDoSomething(function()            saveRet = saveRet and (smallimagePath ~= nil)            func_next(saveRet,smallimagePath,bigImagePath)        end)    end)endfunction WeixinShareTips.createWeixinImagefileWithlogoAndTwoDimension(tofile@R_419_6889@,imgSize)    local function createRenderNodeWithPathPos(pathPos)        local sprite = nil        if pathPos then            sprite = cc.Sprite:create(pathPos.path)            sprite : setposition(pathPos.pos)            sprite : setScale(pathPos.scale)        end        return sprite    end    local function createRenderTextureWithNodes(logoRenderNode,twoDimensionNode,backGroundNode)          -- body        local renderTexture = cc.RenderTexture:create(imgSize.wIDth,imgSize.height)        renderTexture : beginWithClear(0,0)        if backGroundNode and (cc.Director:getInstance():getRunningScene() ~= backGroundNode) then            backGroundNode : getTexture() : setTexParameters(cc.GL_liNEAR,cc.GL_liNEAR,cc.GL_CLAMP_TO_EDGE,cc.GL_CLAMP_TO_EDGE)        end        if backGroundNode then            backGroundNode : visit()        end               if logoRenderNode then            logoRenderNode : visit()        end        if twoDimensionNode then            twoDimensionNode : visit()        end        renderTexture : endTolua()        return renderTexture    end    local function createImagefileWithRenderTexture(renderTexture)        local saveRet = renderTexture : savetofile(tofile@R_419_6889@,cc.IMAGE_FORMAT_JPEG,false)        cc.Director : getInstance() : getTextureCache() : removeTextureForKey(            cc.fileUtils:getInstance():getWritablePath() .. tofile@R_419_6889@)        if saveRet then           return cc.fileUtils:getInstance():getWritablePath() .. tofile@R_419_6889@        else            cc.showtextTips("保存图片失败")            return nil        end    end    local logoNode =  createRenderNodeWithPathPos(logo)    local twoDimensionNode = createRenderNodeWithPathPos(twoDimension)    local backGroundNode = createRenderNodeWithPathPos(backGround)    if not backGroundNode then        backGroundNode = cc.Director:getInstance():getRunningScene()    end        local renderTexture = createRenderTextureWithNodes(logoNode,backGroundNode)    return createImagefileWithRenderTexture(renderTexture)end
总结

以上是内存溢出为你收集整理的cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法全部内容,希望文章能够帮你解决cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1077559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存