cocos2d-x 显示触摸操作(单击显示效果浪潮,对于视频演示)-绩效转型
http://blog.csdn.net/hitwhylz/article/details/26042751
首先是显示触摸操作。
在文章最后。对性能进行一些提升改造。
由于要演示我们的作品。使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, 出现红点或者水波荡漾这种效果), 那样的话演示效果不好。观众就无法直观的了解我们的游戏。
所以考虑增加这个功能。
之后, 走了点弯路。一直在考虑手机本身有没有这个功能。后来找了非常久。
非越狱iPhone是没有这个功能的。
于是乎, 自己写呗。
详细效果例如以下:
实现非常easy,主要用到了一个粒子效果。
详细过程例如以下:
0.导入粒子效果文件. showClick.png + showClick.plist(可在我给出的demo中下载)
1.开启触摸
2.在ccTouchBegan中获取触摸点
3.在该触摸点中加入粒子效果
好了。
以下给出详细代码。
当然, 也能够去我的Github中下载源代码:
https://github.com/colin1994/showClickTest
代码例如以下:(注意:在头文件加入 USING_NS_CC;亦可可是必须加入)
HelloWorld.h
- #ifndef __HELLOWORLD_SCENE_H__
- #define __HELLOWORLD_SCENE_H__
- #include "cocos2d.h"
- using namespace cocos2d;
- class HelloWorld : public cocos2d::CCLayer
- {
- public:
- // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
- virtual bool init();
- // there's no 'id' in cpp, so we recommend to return the class instance pointer
- static cocos2d::CCScene* scene();
- // a selector callback
- void menuCloseCallback(CCObject* pSender);
- // preprocessor macro for "static create()" constructor ( node() deprecated )
- CREATE_FUNC(HelloWorld);
- //进入, 退出响应
- virtual void onEnter();
- virtual void onExit();
- //触屏逻辑函数
- virtual void registerWithTouchDispatcher(void);
- virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
- };
- #endif // __HELLOWORLD_SCENE_H__
HelloWorld.m
- #include "HelloWorldScene.h"
- #include "SimpleAudioEngine.h"
- using namespace cocos2d;
- using namespace CocosDenshion;
- CCScene* HelloWorld::scene()
- {
- // 'scene' is an autorelease object
- CCScene *scene = CCScene::create();
- // 'layer' is an autorelease object
- HelloWorld *layer = HelloWorld::create();
- // add layer as a child to scene
- scene->addChild(layer);
- // return the scene
- return scene;
- }
- // on "init" you need to initialize your instance
- bool HelloWorld::init()
- {
- //////////////////////////////
- // 1. super init first
- if ( !CCLayer::init() )
- {
- return false;
- }
- return true;
- }
- void HelloWorld::menuCloseCallback(CCObject* pSender)
- {
- CCDirector::sharedDirector()->end();
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
- exit(0);
- #endif
- }
- #pragma mark - enter,exit
- //进入响应函数
- void HelloWorld::onEnter()
- {
- CCLayer::onEnter();
- //进入开启触摸
- this->setTouchEnabled(true);
- }
- //退出响应函数
- void HelloWorld::onExit()
- {
- CCLayer::onExit();
- }
- #pragma mark - 触摸事件
- void HelloWorld::registerWithTouchDispatcher()
- {
- //kCCMenuHandlerPriority=-128,将这个值设置为-128的二倍。能够比下边的层的优先级高
- //并且ccTouchBegan的返回值为true,说明其它的层将接受不到这个触摸消息了,仅仅有这个层上边的
- //菜单的优先级比他还要打,所以它上边的菜单是能够接收到触摸消息的
- CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,
- kCCMenuHandlerPriority*2,true);
- }
- //触摸事件
- bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
- {
- //获得触摸点坐标
- CCPoint touchLocation = pTouch->getLocation();
- CCParticleSystemQuad *mParticle = CCParticleSystemQuad::create("showClick.plist");
- mParticle->setScale(0.5f);
- mParticle->setPosition(touchLocation);
- //假设不设置,粒子播放后内存不释放
- mParticle->setAutoRemoveOnFinish(true);
- this->addChild(mParticle);
- return false;
- }
bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
//获得触摸点坐标
CCPoint touchLocation = pTouch->getLocation();
CCParticleSystemQuad *mParticle = CCParticleSystemQuad::create("showClick.plist");
mParticle->setScale(0.5f);
mParticle->setPosition(touchLocation);
//加入ParticleBatchNode
mParticle->retain();
CCParticleBatchNode *batch = CCParticleBatchNode::createWithTexture(mParticle->getTexture());
batch->addChild(mParticle);
this->addChild(batch);
mParticle->release();
return false;
}
cocos2d-x 显示触摸操作(单击显示效果浪潮,对于视频演示)-绩效转型的更多相关文章
- cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)
昨天刚刚參加玩游戏设计大赛, 积累了一些东西. 接下去将会逐个分享出来. 首先是显示触摸操作. 由于要演示我们的作品.使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, ...
- Android源码阅读技巧--查找开发者选项中显示触摸操作源码
在开发者模式下,在开发者选项中,可以勾选“显示触摸操作”,然后只要点击屏幕就会在点击的位置有圈圈显示.如何找到绘制圈圈的代码部分,有什么技巧来阅读代码量这么大的android系统源码呢?以下请跟着小老 ...
- AudioPlayer.js,一个响应式且支持触摸操作的jquery音频插件
AudioPlayer.js是一个响应式.支持触摸操作的HTML5 的音乐播放器.本文是对其官网的说用说明文档得翻译,博主第一次翻译外文.不到之处还请谅解.之处. JS文件地址:http://osva ...
- 10大支持移动“触摸操作”的JavaScript框架
摘要:移动开发行业的发展速度让人目不暇接,也在此大势之下,推出移动网站App成为开发者必经之路,如何让触屏设备 更易使用?如何让网站对触摸手势做出反应并使触摸更友好?所有这一切,皆因JavaScrip ...
- Linux命令之route - 显示和操作IP路由表
转自: http://codingstandards.iteye.com/blog/1125312 用途说明 route命令用于显示和操作IP路由表(show / manipulate the IP ...
- IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)
IOS开发中如何判断程序第一次启动 在软件下载安装完成后,第一次启动往往需要显示一个新手操作引导,来告诉用户怎么操作这个app,这就需要在程序一开始运行就判断程序是否第一次启动,如果是,则显示新手操作 ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- python selenium TouchAction模拟移动端触摸操作(十八)
最近做移动端H5页面的自动化测试时候,需要模拟一些上拉,下滑的操作,最初考虑使用使用selenium ActionChains来模拟操作,但是ActionChains 只是针对PC端程序鼠标模拟的一系 ...
- WPF 程序无法触摸操作?我们一起来找原因和解决方法!
WPF 自诞生以来就带着微软先生的傲慢.微软说 WPF 支持触摸,于是 WPF 就真的支持触摸了.对,我说的是"支持触摸",那种摸上去能点能动的:偶尔还能带点儿多指的炫酷效果.但是 ...
随机推荐
- angular内置指令相关知识
原文地址 https://www.jianshu.com/p/5a5b43a8e91f 大纲 1.angular指令的分类 2.angular指令之——组件 3.angular指令之——属性指令 (n ...
- 怎样实现iMessage群发
怎样实现iMessage群发 Apple公司全线在mac os与ios两个操作系统上内置了FaceTime与iMessage两个应用.完美替代运营商的短信与电话.并且FaceTime与iMessage ...
- [RxJS] Split an RxJS observable with window
Mapping the values of an observable to many inner observables is not the only way to create a higher ...
- php面试题12(多态web服务器共享session的方法:将session存到数据库)($val=&$data[$key];)
php面试题12(多态web服务器共享session的方法:将session存到数据库)($val=&$data[$key];) 一.总结 1.多态web服务器共享session的方法: ...
- git入门基础
git基础 参考: 官网git基础 git 文件的生命周期 文件的生命周期图: git中的文件可以分为4个阶段. Untracked : 这是目录中没有被跟踪的文件,即不在git项目中,使用 git ...
- phpStudy的localhost不能访问怎么解决(相关性)
phpStudy的localhost不能访问怎么解决(相关性) 一.总结 1.注释掉httpd.conf文件中的#ServerName localhost:80 这句话. 2.既然是localho ...
- Ubuntu安装编译OpenCV一键脚本(带ffmpeg)
1.切换到用户文件夹 cd ~ 2.新建一个文件.命名为opencv.sh 脚本例如以下: version="$(wget -q -O - http://sourceforge.net/pr ...
- 如何快糙好猛的使用libfacedetection库【最新版】
前言 最近已经很少看CSDN了.这一年多准备考研,基本上怕是不会再怎么上了.以前有一个http://blog.csdn.net/mr_curry/article/details/51804072 如何 ...
- cordova之File Transfer (Permission denied) 权限导致下载失败 - 简书
原文:cordova之File Transfer (Permission denied) 权限导致下载失败 - 简书 在文件上传时,由于权限问题,会报错(Permission denied),安卓6. ...
- 【records】10.9-10.16
.
