点击事件的listener我用的是EventListenerTouchOneByOne,需要三步
1、实例EventListenerTouchOneByOne;
2、给listener设置onTouchBegan回调;
3、绑定listener和需要监听点击事件的控件;
例子:
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [label](Touch* t,Event *e) { if(label->getBoundingBox().containsPoint(t->getLocation())) { //点击事件回调 Director::getInstance()->replaceScene(ImageScene::createScene()); } return false; }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraPHPriority(listener,label);
切换场景用的函数是void Director::replaceScene(Scene *scene)
切换场景的过渡动画引擎集成了很多可以看http://www.cocos2d-x.org/reference/native-cpp/V3.3rc0/dc/ded/classcocos2d_1_1_transition_scene.html这个
例子:
Director::getInstance()->replaceScene(TransitionFadeBL::create(1,ImageScene::createScene()));