cocos的点击事件响应的话,一般可以考虑两种方法,一种是采用回调函数的方法,另一种是采用Lisener事件监听器。
一、匿名回调函数方法:
Label* testLabel = Label::create("test", "Arial", 30);
MenuItemLabel* labelMenu = MenuItemLabel::create(testLabel, [](Ref* sender){
log("匿名回调");
});
Menu* menu = Menu::create(labelMenu, NULL);
this->addChild(menu, 3);
二、申明函数回调方法:
Label* testLabel = Label::create("test", "Arial", 30);
MenuItemLabel* labelMenu = MenuItemLabel::create(testLabel,CC_CALLBACK_0(changjing::click3, this);
...
void changjing::click3(){
log("申明回调");
}
这样就可以在点击的时候,触发我们想要的事件了。
参考:http://www.cnblogs.com/slysky/p/3824773.html
http://blog.csdn.net/marpools/article/details/24526223