Cocos2d-x 点击事件与切换场景

前端之家收集整理的这篇文章主要介绍了Cocos2d-x 点击事件与切换场景前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

点击事件的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()));

猜你在找的Cocos2d-x相关文章