cocos2dx 3.2截屏功能
2015-06-03 20:51
316 查看
<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);
}
//
// 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);
}
相关文章推荐
- cocospods老是卡在Analyzing dependencies~~
- cocos2d-x 3.6版本学习笔记-内存管理之Node对象
- cocos2d安卓android长音效播放不完全
- cocos2d-x lua 触摸事件
- cocos2d-x lua 使用自定义消息EventCustom
- cocos2d-x lua 实现状态机
- cocos2d-x lua 实现单例(管理类)
- 在 quick-cocos2d-x 中导出 CCFileUtils::getFileData 给Lua使用
- cocos2dx 之 多个Sprite同时进行操作
- Quick-Cocos2d-x的热更新机制实现
- 在MFC 窗口中运行 cocos2d-x 3.2 (一) 基本配置
- 在MFC 窗口中运行 cocos2d-x 3.2 (二) 让其在MFC picture控件中运行
- Cocos2d-X之别踩白块
- quick-cocos2d-x游戏开发【7】——scheduler 定时器
- 【末世旅行之Cocos2d-x】Cocos3.x中对标签Label的更改
- cocos2d-html5 碰撞检測的几种方法
- cocos2dx-3.0------场景切换效果
- cocos2dx中的cocosDenshion对不同平台音频支持格式
- 我的Cocos2d-x学习笔记(十九)CCString、CCArray
- 我的Cocos2d-x学习笔记(十八)CCGridAction