动作回调函数 (CallFunc,CallFuncN,CCCallFuncND)
2015-06-05 21:21
369 查看
动作回调函数 (例子)
bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); /////////////// 动作回掉函数 ///////////////// Sprite* sprite = Sprite::create("button.png"); sprite->setPosition(Vec2(visibleSize.width * 0.2, visibleSize.height * 0.5)); this->addChild(sprite); ActionInterval *move = MoveTo::create(3, Vec2(visibleSize.width * 0.8, visibleSize.height * 0.5)); // 空的动作回调函数 ActionInstant *func = CallFunc::create(this, callfunc_selector(HelloWorld::funcCallBack)); // 带一个参数的动作回掉函数(参数是 Node 类型的) ActionInstant *funcN = CallFuncN::create(this, callfuncN_selector(HelloWorld::funcNCallBack)); // 带两个参数的动作回调函数(参数是 Node 类型的, 传递的数据) ActionInstant *funcND = CCCallFuncND::create(this, callfuncND_selector(HelloWorld::funcNDCallBack),(void*) 10); // 每隔 1s执行一个动作 sprite->runAction(Sequence::create(move, DelayTime::create(1.0f), func, DelayTime::create(3.0f), funcN, DelayTime::create(3.0f), funcND, nullptr)); /////////////// 动作回掉函数 ///////////////// return true; } // 无参的回调函数 void HelloWorld::funcCallBack(){ log("action end"); } // 获取精灵的回调函数;精灵变大 3 倍 void HelloWorld::funcNCallBack(Node *pSender){ Sprite* sprite = (Sprite*)pSender; ActionInterval *scale = ScaleTo::create(1.0f, 3.0f); sprite->runAction(scale); } // 获取精灵和数据的回调函数:精灵移动到(200,200)的位置,并输出 data 的值 void HelloWorld::funcNDCallBack(cocos2d::Node *pSender, void* data){ Sprite* sprite = (Sprite*)pSender; ActionInterval *move = MoveTo::create(1.0f, Vec2(200,200)); sprite->runAction(move); log("data %d", data); }
在精灵运动到指定位置后
1s后控制台才输出 action end 语句
3s后精灵变大3倍
3s后精灵移动到(200,200)位置处并输出 data 10
相关文章推荐
- ActionScript 3.0 学习(二) Flash Builder找不到所需版本的Adobe Flash Player
- java内置数据结构--Map接口与特性
- VNR共享辞书中翻译的转码和代理
- linux下一个C语言flock功能使用 .
- POJ 1979 Red and Black dfs 难度:0
- NGUI使用4——创建动态字体
- Android的TabHost组件-android的学习之旅(四十)
- 三层架构--如何判断一项功能到底属于哪一程
- Android的TabHost组件-android的学习之旅(四十)
- Android的TabHost组件-android的学习之旅(四十)
- CCNA学习指南 IP路由
- Odroid U3 烧写镜像文件
- [hdu]Tempter of the Bone
- OpenStack行业实践和发展趋势
- NGUI使用3——制作图集&自定义按钮&切换按钮图片
- 关于ssh连接主机git连接github失败的问题
- 输入的优化
- HDU 不容易系列之(3)—— LELE的RPG难题
- 【原创视频教程】SqlServer2008视频教程[共9集]
- NGUI使用2——Button -- 按钮