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

  1. #ifndef __HELLOWORLD_SCENE_H__
  2. #define __HELLOWORLD_SCENE_H__
  3. #include "cocos2d.h"
  4. using namespace cocos2d;
  5. class HelloWorld : public cocos2d::CCLayer
  6. {
  7. public:
  8. // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
  9. virtual bool init();
  10. // there's no 'id' in cpp, so we recommend to return the class instance pointer
  11. static cocos2d::CCScene* scene();
  12. // a selector callback
  13. void menuCloseCallback(CCObject* pSender);
  14. // preprocessor macro for "static create()" constructor ( node() deprecated )
  15. CREATE_FUNC(HelloWorld);
  16. //进入, 退出响应
  17. virtual void onEnter();
  18. virtual void onExit();
  19. //触屏逻辑函数
  20. virtual void registerWithTouchDispatcher(void);
  21. virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
  22. };
  23. #endif // __HELLOWORLD_SCENE_H__

HelloWorld.m

  1. #include "HelloWorldScene.h"
  2. #include "SimpleAudioEngine.h"
  3. using namespace cocos2d;
  4. using namespace CocosDenshion;
  5. CCScene* HelloWorld::scene()
  6. {
  7. // 'scene' is an autorelease object
  8. CCScene *scene = CCScene::create();
  9. // 'layer' is an autorelease object
  10. HelloWorld *layer = HelloWorld::create();
  11. // add layer as a child to scene
  12. scene->addChild(layer);
  13. // return the scene
  14. return scene;
  15. }
  16. // on "init" you need to initialize your instance
  17. bool HelloWorld::init()
  18. {
  19. //////////////////////////////
  20. // 1. super init first
  21. if ( !CCLayer::init() )
  22. {
  23. return false;
  24. }
  25. return true;
  26. }
  27. void HelloWorld::menuCloseCallback(CCObject* pSender)
  28. {
  29. CCDirector::sharedDirector()->end();
  30. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
  31. exit(0);
  32. #endif
  33. }
  34. #pragma mark - enter,exit
  35. //进入响应函数
  36. void HelloWorld::onEnter()
  37. {
  38. CCLayer::onEnter();
  39. //进入开启触摸
  40. this->setTouchEnabled(true);
  41. }
  42. //退出响应函数
  43. void HelloWorld::onExit()
  44. {
  45. CCLayer::onExit();
  46. }
  47. #pragma mark - 触摸事件
  48. void HelloWorld::registerWithTouchDispatcher()
  49. {
  50. //kCCMenuHandlerPriority=-128,将这个值设置为-128的二倍。能够比下边的层的优先级高
  51. //并且ccTouchBegan的返回值为true,说明其它的层将接受不到这个触摸消息了,仅仅有这个层上边的
  52. //菜单的优先级比他还要打,所以它上边的菜单是能够接收到触摸消息的
  53. CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,
  54. kCCMenuHandlerPriority*2,true);
  55. }
  56. //触摸事件
  57. bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
  58. {
  59. //获得触摸点坐标
  60. CCPoint touchLocation = pTouch->getLocation();
  61. CCParticleSystemQuad *mParticle =  CCParticleSystemQuad::create("showClick.plist");
  62. mParticle->setScale(0.5f);
  63. mParticle->setPosition(touchLocation);
  64. //假设不设置,粒子播放后内存不释放
  65. mParticle->setAutoRemoveOnFinish(true);
  66. this->addChild(mParticle);
  67. return false;
  68. }

=============
2次改造性能提升
ParticleBatchNode能够引用且仅仅能够引用1个texture(一个图片文件,一个texture图集)。添加到SpriteBatchNode中的ParticleSystem都是在OpenGL ES调用画图函数时绘制的。
 
假设ParticleSystem没有添加到ParticleBatchNode中,OpenGL ES会调用每一个粒子系统的画图函数,这样做效率会比較低。

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 显示触摸操作(单击显示效果浪潮,对于视频演示)-绩效转型的更多相关文章

  1. cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)

    昨天刚刚參加玩游戏设计大赛, 积累了一些东西. 接下去将会逐个分享出来. 首先是显示触摸操作. 由于要演示我们的作品.使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, ...

  2. Android源码阅读技巧--查找开发者选项中显示触摸操作源码

    在开发者模式下,在开发者选项中,可以勾选“显示触摸操作”,然后只要点击屏幕就会在点击的位置有圈圈显示.如何找到绘制圈圈的代码部分,有什么技巧来阅读代码量这么大的android系统源码呢?以下请跟着小老 ...

  3. AudioPlayer.js,一个响应式且支持触摸操作的jquery音频插件

    AudioPlayer.js是一个响应式.支持触摸操作的HTML5 的音乐播放器.本文是对其官网的说用说明文档得翻译,博主第一次翻译外文.不到之处还请谅解.之处. JS文件地址:http://osva ...

  4. 10大支持移动“触摸操作”的JavaScript框架

    摘要:移动开发行业的发展速度让人目不暇接,也在此大势之下,推出移动网站App成为开发者必经之路,如何让触屏设备 更易使用?如何让网站对触摸手势做出反应并使触摸更友好?所有这一切,皆因JavaScrip ...

  5. Linux命令之route - 显示和操作IP路由表

    转自:  http://codingstandards.iteye.com/blog/1125312 用途说明 route命令用于显示和操作IP路由表(show / manipulate the IP ...

  6. IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)

    IOS开发中如何判断程序第一次启动 在软件下载安装完成后,第一次启动往往需要显示一个新手操作引导,来告诉用户怎么操作这个app,这就需要在程序一开始运行就判断程序是否第一次启动,如果是,则显示新手操作 ...

  7. 仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图:       ...

  8. python selenium TouchAction模拟移动端触摸操作(十八)

    最近做移动端H5页面的自动化测试时候,需要模拟一些上拉,下滑的操作,最初考虑使用使用selenium ActionChains来模拟操作,但是ActionChains 只是针对PC端程序鼠标模拟的一系 ...

  9. WPF 程序无法触摸操作?我们一起来找原因和解决方法!

    WPF 自诞生以来就带着微软先生的傲慢.微软说 WPF 支持触摸,于是 WPF 就真的支持触摸了.对,我说的是"支持触摸",那种摸上去能点能动的:偶尔还能带点儿多指的炫酷效果.但是 ...

随机推荐

  1. 在word中使用notepad++实现代码的语法高亮 分类: C_OHTERS 2013-09-22 10:38 2273人阅读 评论(0) 收藏

    转载自:http://blog.csdn.net/woohello/article/details/7621651 有时写文档时需要将代码粘贴到word中,但直接粘贴到word中的代码虽能保持换行与缩 ...

  2. Django之富文本编辑器kindeditor 及上传

    1.什么是富文本编辑器 百度百科(https://baike.baidu.com/item/%E5%AF%8C%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8 ...

  3. Android JobService的使用及源码分析

    Google在Android 5.0中引入JobScheduler来执行一些需要满足特定条件但不紧急的后台任务,APP利用JobScheduler来执行这些特殊的后台任务时来减少电量的消耗.本文首先介 ...

  4. 常用服务器ftp、ssh

    1. Linux常用服务器构建-ftp服务器 ftp服务器 FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议". 用于Int ...

  5. UTC时间与当地时间的转换关系?

    UTC时间与当地时间转换关系? 一.总结 1.UTC +时区差=本地时间 2.UTC是世界统一时间 二.UTC时间是什么 1.UTC时间 协调世界时,又称世界统一时间.世界标准时间.国际协调时间.由于 ...

  6. [Angular] USING ZONES IN ANGULAR FOR BETTER PERFORMANCE

    Link to the artical. Zone detects any async opreations. Once an async oprations happens in Angular, ...

  7. [NPM] Use a shorthand syntax for running multiple npm scripts with npm-run-all

    Running multiple scripts in series or in parallel can become very verbose. Using a tool such as npm- ...

  8. C++ public、protected、private 继承方式的区别

    访问修饰符 public.protected.private,无论是修饰类内成员(变量.函数),还是修饰继承方式,本质上实现的都是可见性的控制. Difference between private, ...

  9. Redis+Mysql模式和内存+硬盘模式的异同

    http://www.open-open.com/lib/view/open1346029825942.html 学习任何新知识,都是一个循序渐进的过程,从刚开始的懵懂无知,到简单熟悉,然后突然的彻悟 ...

  10. 学习web开发遇到几个细节问题

    1.在jsp中使用jsp表达式在input标签中时,避免直接和结束"/"相连 2.提取input select 标签内的内容,使用...value提取其值 3.form中含有一个o ...