cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)
2014-05-17 08:37
375 查看
昨天刚刚参加玩游戏设计大赛, 积累了一些东西。接下去将会逐个分享出来。
首先是显示触摸操作。
因为要演示我们的作品。使用试玩过程中, 如果没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, 出现红点或者水波荡漾这样的效果), 那样的话演示效果不好。观众就无法直观的了解我们的游戏。所以考虑加入这个功能。
之后, 走了点弯路。一直在考虑手机本身有没有这个功能,后来找了很久。非越狱iPhone是没有这个功能的。
于是乎, 自己写呗。
具体效果如下:
实现很简单,主要用到了一个粒子效果。
具体步骤如下:
0.导入粒子效果文件. showClick.png + showClick.plist(可在我给出的demo中下载)
1.开启触摸
2.在ccTouchBegan中获取触摸点
3.在该触摸点中添加粒子效果
好了。下面给出具体代码。
当然, 也可以去我的Github中下载源码:
https://github.com/colin1994/showClickTest
代码如下:
HelloWorld.h
HelloWorld.m
学习的路上, 与君共勉。
首先是显示触摸操作。
因为要演示我们的作品。使用试玩过程中, 如果没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, 出现红点或者水波荡漾这样的效果), 那样的话演示效果不好。观众就无法直观的了解我们的游戏。所以考虑加入这个功能。
之后, 走了点弯路。一直在考虑手机本身有没有这个功能,后来找了很久。非越狱iPhone是没有这个功能的。
于是乎, 自己写呗。
具体效果如下:
实现很简单,主要用到了一个粒子效果。
具体步骤如下:
0.导入粒子效果文件. showClick.png + showClick.plist(可在我给出的demo中下载)
1.开启触摸
2.在ccTouchBegan中获取触摸点
3.在该触摸点中添加粒子效果
好了。下面给出具体代码。
当然, 也可以去我的Github中下载源码:
https://github.com/colin1994/showClickTest
代码如下:
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; }
学习的路上, 与君共勉。
相关文章推荐
- cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)-性能改造
- cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)
- cocos2d-x 显示触摸操作(单击显示效果浪潮,对于视频演示)-绩效转型
- 设计input搜索框提示文字点击消失的效果,提示文字与输入显示不同----->特别推荐
- 点击显示隐藏菜单,动画效果,半透明,支持所有浏览器
- js点击显示全部内容(用于内容比较长时)
- 分组图表操作视频演示
- asp 实现视频显示的效果函数
- Hibernate的问题--增删改不录数据库,页面上能够显示当时操作效果
- 多屏控制处理器双屏显示卡边缘融合视频叠加与大屏幕投影效果[转]
- 点击显示隐藏菜单,动画效果,半透明,支持所有浏览器
- vc++实现avi文件的操作 用于视频解析及录制(转)
- JAVA源代码!可以显示水波效果!
- [Android]点击按钮进入下一个Activity时显示动画效果
- 点击internet explorer 显示该文件没有程序与之关联来执行该操作 请在控制面板的文件夹选项中创建关联程解决方案
- 点击显示隐藏菜单,动画效果,半透明,支持所有浏览器
- 多图展示点击切换效果模拟的flash效果,点小图放大显示,再点恢复默认。
- 多图展示点击切换效果模拟的flash效果,点小图放大显示,再点恢复默认。
- 视频:Windows 8桌面及任务栏效果演示
- 点击显示隐藏菜单,动画效果,半透明,支持所有浏览器