cocos2dx-lua 截屏

本文介绍了一个使用Cocos2d-x游戏引擎实现截图功能的代码示例。通过调用c++自带的captureScreen方法,可以在游戏场景中进行截图,并将截图保存为文件。代码还展示了如何在截图成功后在场景中显示截图图片。

– 直接上代码
function layer:shotScene()
local callBack = function (isS,outFile)
if isS then
local sceneImage = self.rootNode:getChildByName(“scene_image”)
if sceneImage == nil then
sceneImage = ccui.ImageView:create()
sceneImage:loadTexture(outFile)
sceneImage:setPosition(640,360)
sceneImage:setName(“scene_image”)
sceneImage:setScale(0.5)
self.rootNode:addChild(sceneImage)
end
– self.updateBtn:loadTextureNormal(outFile)
print(“截图成功”)
cc.FileUtils:getInstance():removeFile(outFile)
else
print(“截图失败”)
end
end
local fileName = “screenshot”…tostring(os.time())…".png"
–c++自带方法
cc.utils:captureScreen(callBack,fileName)
end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值