cocos2d-x 3.2 截屏

本文介绍了cocos2d-x3.2版本中如何使用ccUtils.h文件提供的功能实现截屏操作,包括调用方法、参数解释及演示代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


cocos2d-x 3.2 版本添加了截屏功能,方法位于 ccUtils.h 文件中


 void captureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename);
    


两个参数: 1、判断是否截图成功 以及 返回截图存储的路径

           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"); 
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值