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. FZU 1650 1752 a^b mod c

    http://acm.fzu.edu.cn/problem.php?pid=1752 http://acm.fzu.edu.cn/problem.php?pid=1650 给跪了. 我的快速幂会越界. ...

  2. SpringBoot学习:获取yml和properties配置文件的内容(转)

    项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821 (一)yml配置文件: pom.xml加入依赖: <!-- 支持 @Configu ...

  3. URL validation failed. The error could have been caused through the use of the browser&#39;s navigation

    URL validation failed. The error could have been caused through the use of the browser's navigation ...

  4. 一起talk C栗子吧(第八十三回:C语言实例--进程间通信概述)

    各位看官们,大家好,前二回中咱们说的是进程停止的样例,这一回咱们说的样例是:进程间通信.闲话休提,言归正转.让我们一起talk C栗子吧! 看官们.每一个进程都拥有自己的资源,假设不同进程之间须要共享 ...

  5. 在shell脚本中调用sqlplus 分类: H2_ORACLE 2013-06-23 13:01 1437人阅读 评论(0) 收藏

    #!/bin/bash sqlplus dc_file_data_js/dc_file_data_js << EOF1 set linesize 500; set pagesize 100 ...

  6. 20+ 个很有用的 jQuery 的 Google 地图插件 (英语)

    20+ 个很有用的 jQuery 的 Google 地图插件 (英语) 一.总结 一句话总结:英语提上来我才能快速去google上面找资源啊.google上面的资源要比百度丰富很多,然后有了英语就可以 ...

  7. js调用百度地图api

    <!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">   ...

  8. python 多线程拷贝单个文件

    # -*- coding: utf-8 -*- # @author: Tele # @Time : 2019/04/04 下午 12:25 # 多线程方式拷贝单个文件 import threading ...

  9. 设置非ARC

    设置非ARC:   在build phase 设置中compile sources 选择非arc文件,设置键值为-fno-objc-arc

  10. 课后作业11--使用SQL语句创建一个数据库

    use master if db_id ('test') is not null--判断test数据库是否存在 drop database [test]--如果存在 删除test go--完成查找删除 ...