cocos3.8屏幕截图

2023-08-24 13:23:18 浏览数 (1)

代码语言:javascript复制
utils::captureScreen(CC_CALLBACK_2(HelloWorld::afterCapture, this), "D:/MyCocosProj/FallDown/Resources/ScreenShot.png");

然后在回调函数

代码语言:javascript复制
void HelloWorld::afterCapture(bool succeed, const std::string& outputFile)
{
	if (succeed)
	{
		CCLOG("outputFile = %s", outputFile.c_str());
		//显示截图
		Sprite* sp = Sprite::create(outputFile);
		sp->setPosition(ccp(100,100));
		this->addChild(sp);
		sp->setScale(0.25); //放缩
	}
	else
	{
		CCLOG("Capture screen failed.");
	}
}

0 人点赞