cocos2d-x 3.2 版本添加了截屏功能,方法位于 ccUtils.h 文件中
void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename);
2、所要存储的截图文件名称
写了如下demo:
//添加精灵 点击截屏按钮
auto screen_btn=MenuItemImage::create("buttonA.png","buttonB.png",CC_CALLBACK_1(HelloWorld::screenShoot,this));
screen_btn->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
auto menu = Menu::create(closeItem,screen_btn, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
void HelloWorld::screenShoot(Ref* pSender)
{
utils::captureScreen([](bool b,std::string name){ CCLOG("the pic is saved: %s,file name:%s",b?"success":"field",name.c_str()); },"screenShot.png");
}