cocos2dx的utils类中包含截图功能,使用方法如下:
cc.utils:captureScreen(function(successed,outputFile)--第一个参数是截图成功或者失败的回调函数
if successed then--如果成功,返回true,否则返回nil
local sp = cc.Sprite:create(outputFile)
end
end,"captureTexture.png")第二个参数是保存文件名
看cocos源代码,截图文件会将保存在可写路径中或者绝对路径中,
std::shared_ptr<Image> image(new Image);
if (image)
{
image->initWithRawData(flippedBuffer.get(), width * height * 4, width, height, 8);
if (FileUtils::getInstance()->isAbsolutePath(filename))
{
outputFile = filename;
}
else
{
CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!");
outputFile = FileUtils::getInstance()->getWritablePath() + filename;
}
succeed = image->saveToFile
转载请注明出处,from 博客园 HemJohn
本文详细介绍了Cocos2dx中的截图功能及其使用方法。通过cc.utils:captureScreen()函数可以轻松实现截图,并提供了回调函数来处理截图是否成功的逻辑。此外,还解释了截图文件的保存路径及具体的实现细节。
4987

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



