cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法
来源:互联网 发布:js中字符串转json 编辑:程序博客网 时间:2024/05/18 09:17
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, pos = cc.p(imgSize.width / 2, imgSize.height / 2), scale = imgScale } local smallImagePath = WeixinShareTips.createWeixinImageFileWithLogoAndTwoDimension("smallWeixinShare.jpg", backGround, nil, nil, imgSize) delayDoSomething(function() saveRet = saveRet and (smallImagePath ~= nil) func_next(saveRet, smallImagePath, bigImagePath) end) end)endfunction WeixinShareTips.createWeixinImageFileWithLogoAndTwoDimension(toFileName, backGround, logo, twoDimension, 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,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(toFileName, cc.IMAGE_FORMAT_JPEG, false) cc.Director : getInstance() : getTextureCache() : removeTextureForKey( cc.FileUtils:getInstance():getWritablePath() .. toFileName) if saveRet then return cc.FileUtils:getInstance():getWritablePath() .. toFileName 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, twoDimensionNode, backGroundNode) return createImageFileWithRenderTexture(renderTexture)end
0 0
- cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法
- Cocos2D绘制纹理的一般方法
- cocos2d使用纹理渲染需要注意的地方
- cocos2d - 纹理的选择
- cocos2d查看OpenGL当前所绑定的纹理
- Cocos2d-X的纹理(2)
- Cocos2d-X的纹理(1)
- Cocos2D粒子发射器的纹理
- 渲染世界的OPENGL<14>纹理进阶-多重纹理
- 渲染世界的OPENGL<16>纹理进阶-纹理数组
- cocos2d-x 图片纹理优…
- cocos2d开发学习五:精灵节点CCSpriteBatchNode的渲染和纹理集Texture Atlases内存优化
- cocos2d开发学习五:精灵节点CCSpriteBatchNode的渲染和纹理集Texture Atlases内存优化
- Ogre中渲染到纹理的步骤
- Direct3D渲染到纹理的一点技巧
- OpenGL的渲染成纹理技术(转)
- 使用渲染纹理的制作摄像头
- 关于VR边纹理材质的渲染
- android java 如何判断一个url地址为有效url
- 五种简单Dialog的使用,以及时间,日期Dialog中onDateSet,onTimeSet被执行两次的Bug
- PATB1009
- 随笔笔记三——关于SpringMVC接收请求参数和向页面传递参数
- 在CentOS6.5搭建Qt5环境
- cocos2d-lua 不渲染纹理,保存当前场景纹理为图片的方法
- Mac下如何隐藏.DS_Store文件的方法
- 《JavaScript高级程序设计》读书笔记(三):面向对象
- angular 利用控制器中的变量动态生成tab选项卡
- sqlite优化
- python子进程模块subprocess详解与应用实例 一
- python子进程模块subprocess详解与应用实例 之二
- JDBC操作总结
- HttpClient对象相关方法的操作