cocos2d-x CCCallFuncN中node CCCallFuncND中data
来源:互联网 发布:sql server 分组查询 编辑:程序博客网 时间:2024/05/17 04:50
CCCallFuncN:
1 CCCallFuncN *instant = new CCCallFuncN;
2 instant->initWithTarget(this, callfuncN_selector(ActionCallFunc::callback2));
3 m_grossini->runAction(instant);
4
5 void ActionCallFunc::callback2(CCNode* pSender)
6 {
7 CCSize s = CCDirector::sharedDirector()->getWinSize();
8 label->setPosition(CCPointMake( s.width/4*2,s.height/2));
9 pSender->setPosition( ccp(0, 0) );
10 }
node即指代runAction的node节点;这样当触发callback2的时候即可通过pSender来改变m_grossini的一些状态。
CCCalFuncND:
1 CCCallFuncND *instant2 = new CCCallFuncND;
2 instant2->initWithTarget(this, callfuncND_selector(ActionCallFunc::callback3), (void*)"fgd");
3
4 void ActionCallFunc::callback3(CCNode* pTarget, void* data)
5 {
6 CCSize s = CCDirector::sharedDirector()->getWinSize();
7 CCLabelTTF *label = CCLabelTTF::labelWithString("fgd", "Marker Felt", 16);
8 label->setPosition(CCPointMake( s.width/4*3,s.height/2));
9 addChild(label);
10 }
Data可以将数据指针传进去,不过类型丢了必须强转。
virtual bool initWithTarget (SelectorProtocol *pSelectorTarget, SEL_CallFuncND selector, void *d);现在对SelectorProtocol不太明白,为什么不是node,要是node的话我可以理解成父节点(psender的父节点),但是为啥是SelectorProtocol呢?
SelectorProtocol:
CCNode是SelectorProtocol的子类
依次类推
CCCallFunc
不带node,也不带数据
CCCallFunc* func = new CCCallFunc;
func->initWithTarget(this,callfunc_selector(HSGamePairLayer::Shake()));
或者
- CCFiniteTimeAction* actions= CCSequence::actions(action,
- CCCallFunc::actionWithTarget(this,callfunc_selector(MyClass::callBackAnim)),NULL);
CCCallFuncO,回调,O表示CCObject,CCCallFunco可以带CCObject参数的函数
[cpp]
CCSequence::actions(CCCallFuncO::actionWithTarget(this, callfuncO_selector(ExtendActionLayer::onCallBack2), CCInteger::create(2));
void ExtendActionLayer::onCallBack2(CCObject* data)
{
CCInteger* num = dynamic_cast<CCInteger*>(data);
pSender->runAction(CCTintBy::actionWithDuration(num->getValue(), 255, 0, 255));
}
在游戏设计时,我们需要不断的改变屏幕显示来反映游戏操作的效果,最简单的就是提示用户已经进行的游戏时间。为此,我们需要使用cocos2d-x内置的任务调度机制,即CCNode的schedule成员函数。
void schedule (SEL_SCHEDULE selector) schedules a selector.
void schedule (SEL_SCHEDULE selector, ccTime interval) schedules a custom selector with an interval time in seconds.
void unschedule (SEL_SCHEDULE selector) unschedules a custom selector.
void unscheduleAllSelectors (void) unschedule all scheduled selectors: custom selectors, and the 'update' selector. cocos2d-x中的schedule有两种作用:
1)定时执行方法
例如,每隔1秒就执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 1.0f);
...
void GameLayer::step(ccTime dt)
{
...
}
例如, 延时 5秒执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 5.0f);
...
void GameLayer::step(ccTime dt)
{
this->unschedule(schedule_selector( GameLayer::step ));
...
}
0 0
- cocos2d-x CCCallFuncN中node CCCallFuncND中data
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中回调函数CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- cocos2d-x 之 CCCallFunc、CCCallFuncN 、CCCallFuncND区别
- cocos2d-x 之 CCCallFunc CCCallFuncN CCCallFuncND
- ocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d中CCCallFuncND传参数的注意事项
- cocos2d中CCCallFuncND传参数的注意事项
- CCCallFunc、CCCallFuncN和CCCallFuncND
- 20140311记录
- file_operations数据结构分析
- Dedecms 文件目录结构分析
- 【CBO】配置查询优化器(参数与统计信息的调整)
- mtk rda 从bootload开始分析如何加载lcd驱动
- cocos2d-x CCCallFuncN中node CCCallFuncND中data
- Java8:使用新JS解释器Nashorn编译Lambda表达式
- Linux下查看文件和文件夹大小
- Linux Tomcat Https 访问配置!
- cygwin 批处理 运行 build_native.sh
- 关于 Unchecked cast from Iterator to Iterator String 提示
- ajax请求php页面中生成的session,无法在其他普通php页面使用
- Linux Mint + Nginx 1.5.11搭建SSL/HTTPS/SPDY服务器
- Java数字摘要 MD5