cocos2dx 3.2截屏功能
发布时间:2020-12-14 21:26:09 所属栏目:百科 来源:网络整理
导读:1JNSaveScreenUtils.h //// JNSaveScreenUtils.h// JNTest//// Created by jianan on 15/6/3.////#ifndef __JNTest__JNSaveScreenUtils__#define __JNTest__JNSaveScreenUtils__#include "cocos2d.h"USING_NS_CC;#includestringusing namespace std;#define
<1>JNSaveScreenUtils.h // // JNSaveScreenUtils.h // JNTest // // Created by jianan on 15/6/3. // // #ifndef __JNTest__JNSaveScreenUtils__ #define __JNTest__JNSaveScreenUtils__ #include "cocos2d.h" USING_NS_CC; #include<string> using namespace std; #define winSize Director::getInstance()->getWinSize() class JNSaveScreenUtils : public Ref { public: JNSaveScreenUtils(); ~JNSaveScreenUtils(); static JNSaveScreenUtils* getInstance(); void captureScreen(string fileName); private: CC_SYNTHESIZE(string,_saveFilePath,SaveFilePath); }; #endif /* defined(__JNTest__JNSaveScreenUtils__) */<2>JNSaveScreenUtils.cpp // // JNSaveScreenUtils.cpp // JNTest // // Created by jianan on 15/6/3. // // #include "JNSaveScreenUtils.h" using namespace utils; static JNSaveScreenUtils* instance = NULL; JNSaveScreenUtils::JNSaveScreenUtils(){ } JNSaveScreenUtils::~JNSaveScreenUtils(){ } JNSaveScreenUtils* JNSaveScreenUtils::getInstance(){ if(!instance){ instance = new JNSaveScreenUtils(); } return instance; } void JNSaveScreenUtils::captureScreen(string fileName){ //void captureScreen(const std::function<void(bool,const std::string&)>& afterCaptured,const std::string& filename); ::captureScreen([](bool b,string name){ log("the pic is saved: %s,file name:%s",b?"success":"field",name.c_str()); },fileName); _saveFilePath = FileUtils::getInstance()->getWritablePath() + fileName; }<3> bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } this->setTag(999); Sprite* sp = Sprite::create("HelloWorld.png"); sp->setPosition(Vec2(winSize.width/2,winSize.height/2)); this->addChild(sp); scheduleOnce(schedule_selector(HelloWorld::Main),1.0f); return true; } void HelloWorld::Main(float dt){ string filePath = JNSaveScreenUtils::getInstance()->getSaveFilePath(); //利用截屏图片来创造新的精灵 Sprite* sp = Sprite::create(filePath); sp->setPosition(winSize.width/3,winSize.height/3); addChild(sp); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |