NotificationCenter的基本使用

NotificationCenter的基本使用:</span>
init方法中:</span>
NotificationCenter::getInstance()->addObserver(this,callfuncO_selector(HelloWorld::call2),"abc",nullptr); //添加观察对象  
	
	auto b1 = MenuItemImage::create("CloseNormal.png","CloseNormal.png",CC_CALLBACK_0(HelloWorld::call,this)); //按钮   
	auto menu = Menu::create(b1,nullptr);
	this->addChild(menu);

 
对应的方法:</span>
void HelloWorld::call()
{
log("call()");
NotificationCenter::getInstance()->postNotification("abc",this);
}


void HelloWorld::call2(Ref* obj)
{
log("call2()");
auto s = Sprite::create("CloseNormal.png");
s->setPosition(Vec2(100,100));
this->addChild(s);
}
</pre><pre name="code" class="cpp">最后:
HelloWorld::~HelloWorld()
{
<span style="white-space:pre">	</span>NotificationCenter::getInstance()->removeObserver(this,"abc");  //取消监听   
<span style="white-space:pre">	</span>//NotificationCenter::getInstance()->removeAllObservers(this);
}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...