The Event Callback Function interfaces after 3.0 are different, such as the menu_selector () of the button and schedule_selector of update. The new callback interface is replaced by four CC_CALLBACK interfaces.
The following describes some different calling methods:
2.0MenuItemImage* item =MenuItemImage::create("","",this,menu_selector(HelloWorld::callback));3.0auto item = MenuItemImage::create("","",CC_CALLBACK1(HelloWorld::callback,this));
Someone may ask how to change the callback function of the button? If you continue to use setTarget ();, it will not work.
3.0 is replaced. The parameters are as follows:
SetCallback (const ccMenuCallback & callback );
Here we can see a new word:
What is this dish of cake? Hahahaha, if you ask me, you will ask the wrong person !!! I can only tell you how to use it.
First, we can see from the parameter changes in setTarget () and setCallback () that ccMenuCallback actually contains the parameters of Object * rec and SEL_MenuHandler selector. For example:
2.0Item->setTarget(this,menu_selector(HelloWorld::callback));3.0Item->setCallback(CC_CALLBACK1(HelloWorld::callback,this));
Well, that's the case. How do you feel that there is no depth in it? Sorry, it's a bit like a "stupid Wood" tone.
Example:
1) callback functions without Parameters
2.0CallFunc::create(this,callfunc_selector(ActionSequence2::callback1));void ActionSequence2::callback1(){};3.0CallFunc::create(CC_CALLBACK_0(ActionSequence2::callback1,this)),void ActionSequence2::callback1(){};
2) callback functions with Parameters
2.0CCSequence* seq = CCSequence::create(MoveBy::create(2.0f,ccp(150,0)),CallFuncN::create(this,callfuncN_selector(ActionCallFunc::callback)),NULL);3.0 auto action = Sequence::create( MoveBy::create(2.0f, Point(150,0)), CallFuncN::create( CC_CALLBACK_1(ActionCallFuncN::callback, this)), NULL);
: CC_CALLBACK0 is a callback function without parameters, and CC_CALLBACK1 is a callback function with parameters.
Now that action is mentioned, let's talk about the new usage of Callfunc in 3.0 (the previous version should not ...)
Auto action1 = CallFunc: create (
});
Note that in the red part, a new callback function is required for the previously called callback. Although this is not a problem, if more callback is used and the callback code is just a few lines, the previous practice is a little unbearable. Now, you can directly write the function code to be called back after the action is executed to the creation. Is it much more convenient.
auto touchListener = EventListenerTouchOneByOne::create();touchListener->setSwallowTouches(true); touchListener->onTouchBegan = CC_CALLBACK_2(MyMenu::onTouchBegan, this);touchListener->onTouchMoved = CC_CALLBACK_2(MyMenu::onTouchMoved, this);touchListener->onTouchEnded = CC_CALLBACK_2(MyMenu::onTouchEnded, this);touchListener->onTouchCancelled = CC_CALLBACK_2(MyMenu::onTouchCancelled, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
Well, now we know that. Continue to make up later.
Reprinted please indicate Source Address: http://blog.csdn.net/start530/article/details/18216679