cocos2d-x CCCallFuncN中node CCCallFuncND中data
2014-03-11 18:06
218 查看
CCCallFuncN:
node即指代runAction的node节点;这样当触发callback2的时候即可通过pSender来改变m_grossini的一些状态。
CCCalFuncND:
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成员函数。
cocos2d-x中的schedule有两种作用:
1)定时执行方法
例如,每隔1秒就执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 1.0f);
...
void GameLayer::step(ccTime dt)
{
...
}
2)延时执行方法
例如, 延时 5秒执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 5.0f);
...
void GameLayer::step(ccTime dt)
{
this->unschedule(schedule_selector( GameLayer::step ));
...
}
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. |
1)定时执行方法
例如,每隔1秒就执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 1.0f);
...
void GameLayer::step(ccTime dt)
{
...
}
2)延时执行方法
例如, 延时 5秒执行GameLayer类的方法step(ccTime dt)。
this->schedule(schedule_selector(GameLayer::step), 5.0f);
...
void GameLayer::step(ccTime dt)
{
this->unschedule(schedule_selector( GameLayer::step ));
...
}
相关文章推荐
- spritex工具的使用方法
- cocos2d-x学习日志(15) --公告栏的实现(文字左右移动)
- cocos2dx创建android独立工程及eclipse编译
- cocos2dx进阶学习之CCLayer
- cocos2d-x中CCLabelAtlas的小图片拼接
- Cocos2d 中的Sprite大小调整问题
- cocostudio中有一些不太适应的功能
- 记录一下刚才看的RenderTexture的功能
- cocos2d_x 问题汇总
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- lua cocos2d-x lua中每次Build都不更新Resource下面的文件,怎样使xcode每次Build都更新Resource下的lua文件
- 使用Cocos2d-x实现微信“天天爱消除”炫耀button特效
- Mac下 Xcode5+,cocos2d-x2.2(或者cocos2d-x2.1.5)Android,eclipse(2013 September版本)跨平台环境配置以及创建跨平台项目
- COCOS2DX-LUA 脚本开发 使用tolua++编译pkg,从而创建自定义类让Lua脚本使用
- XCode5.0和cocos2d-x-3.0beta 创建HelloWorld工程
- 用 python 创建 cocos2dx 项目工程
- Windows7 64位系统搭建Cocos2d-x-2.2.1最新版以及Android交叉编译环境(详细教程)
- cocos2d-x中,怎么开启debugDraw?
- 使用eclipse调试cocos2d-x C++ 代码(编写+真机调试,放弃VS)
- Cocos2d-x 学习资料推荐