在cocos2dx中的pushScene()中应用截屏函数
来源:互联网 发布:杨玉环历史评价知乎 编辑:程序博客网 时间:2024/05/05 19:35
在cocos2dx中,pushScene创建一个场景,而场景的背景是黑色的,目前我还没有找到合适的方法使其透明,所以在网上找到一个方法替代,就是截屏
先上代码:
void ControlLayer::gameOverBtn(Ref* pSender){//获取屏幕大小auto visibleSize=Director::getInstance()->getVisibleSize();//创建一个RenderTexture对象,用于保存截取的图片RenderTexture* texture = RenderTexture::create(visibleSize.width, visibleSize.height);//开始截屏texture->begin();//得到当前正在运行的场景并截取图片,截取图片的范围是visibleSize.width, visibleSize.heightDirector::getInstance()->getRunningScene()->visit();texture->end();//把截取的图片传递给要弹出的场景内Director::getInstance()->pushScene(GameOverScene::createScene(texture));}
TenderTexture 命名空间为cocos2d::
包含头文件#include“cocos2d.h”
然后再对应的场景中创建如下代码:
GameOverScene是一个继承Layer的自定义类
类中包含函数:
static cocos2d::Scene * createScene(cocos2d::RenderTexture * spr);
这个是函数的实现:
Scene * GameOverScene::createScene(RenderTexture *spr){Scene * scene = Scene::create();GameOverScene * layer = GameOverScene::create();scene->addChild(layer, 1);auto visibleSize = Director::getInstance()->getVisibleSize();auto s = Sprite::createWithTexture(spr->getSprite()->getTexture());s->setPosition(visibleSize / 2);s->setScaleY(-1);s->setOpacity(50);scene->addChild(s, 1);return scene;}
这样就可以在新场景中看到原场景的游戏内容了:
如下图所示
0 0
- 在cocos2dx中的pushScene()中应用截屏函数
- 在cocos2dx中应用protobuf
- 在cocos2dx中应用protobuf
- cocos2dx replaceScene、popScene、pushScene的区别
- C语言中结构体在函数中的应用
- ORACLE中DECODE()函数在数据统计中的应用
- C语言中结构体在函数中的应用
- C语言中结构体在函数中的应用 .
- C语言中结构体在函数中的应用
- C语言中结构体在函数中的应用
- C语言中结构体在函数中的应用
- MySQL中group_concat函数在项目中的应用
- 指针在函数中的应用
- 指针在函数中的应用
- cocos2dx中的随机函数
- cocos2dx关于在c/c++中调用lua函数
- 在android studio中导入cocos2dx中的android studio项目
- Python的Numpy库中的 nonzero函数,及应用在 hardlim硬限幅函数中
- 11.函数传指针
- Error Handling In Go, Part I
- 计算未来:年轻程序猿如何凑够540万供老年花费
- 递归方法求阶乘
- 前段:eventsource
- 在cocos2dx中的pushScene()中应用截屏函数
- QtSoap开发web services客户端程序
- win8.1系统中oracle11g数据库无法使用sqlplus / as sysdba登录问题
- touch 命令
- Android ui 字体 控件大小 颜色
- 12.指针-数组-函数参数
- 移动App架构设计
- Android中dp和px之间进行转换
- Monkey and Banana(DAG上的动态规划问题)