cocos2d-x lua cc.RenderTexture 生成快照使用

function  UIPosterShare:QRCodePosterMake()
    print("生成二维码海报快照")
    if cc.FileUtils:getInstance():isFileExist(self.filePath) then return end
    local cachePoster = cc.Director:getInstance():getTextureCache():addImage("res/ac_poster.png")
    local cacheQrcode = cc.Director:getInstance():getTextureCache():addImage("res/QRCode.jpg")
    local posterSprite = cc.Sprite:createWithTexture(cachePoster)
    local codeSprite = cc.Sprite:createWithTexture(cacheQrcode)
    local posterSize = posterSprite:getContentSize()
    local codeSize = codeSprite:getContentSize()
    local qrcSize = 220
    codeSprite:setScale(qrcSize/codeSize.width)
    codeSprite:setPosition(codeSize.width/2+qrcSize/2+15,qrcSize/2+18)
    posterSprite:addChild(codeSprite)
    posterSprite:setPosition(posterSize.width/2,posterSize.height/2)
    posterSprite:retain()
    local render = cc.RenderTexture:create(posterSize.width,posterSize.height)
    render:addTo(self)
    render:beginWithClear(0, 0, 0, 0)
    render:setSprite(posterSprite)
    posterSprite:visit()
    render:endToLua()
    render:saveToFile("res/poster.png")
end

 

你可能感兴趣的:(cocos2d-x lua cc.RenderTexture 生成快照使用)