– 直接上代码
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
cocos2dx-lua 截屏
最新推荐文章于 2021-04-25 16:21:07 发布
本文介绍了一个使用Cocos2d-x游戏引擎实现截图功能的代码示例。通过调用c++自带的captureScreen方法,可以在游戏场景中进行截图,并将截图保存为文件。代码还展示了如何在截图成功后在场景中显示截图图片。

7828

被折叠的 条评论
为什么被折叠?



