Cocos2dx 3.1.1 之 监听器、特效切换场景、动作、检测碰撞、回调函数

	//首先创建一个精灵,点击这精灵切换场景
	auto * sprite = Sprite::create("HelloWorld.png");
	sprite->setPosition(200, 200);
	this->addChild(sprite);

	//监听器
	auto * listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [ttf, sprite, this](Touch * t, Event * e){
		
		if (sprite->getBoundingBox().containsPoint(t->getLocation())){//检测碰撞
			//特效切换场景
			//Director::getInstance()->replaceScene(TransitionFade::create(2,HelloWorld::createScene()));
			//动作
			auto * to = MoveTo::create(3, CCPoint(300,300));
			//auto * re = Repeat::create(RotateBy::create(0.5, 18000), 3);
			auto * ro = RotateBy::create(3, 180000);
			//callfunc
			auto * se = Sequence::create(to, ro, CallFunc::create([](){
				MessageBox("callfunc", "lx");
			}), NULL);
			auto * sp = CCSpawn::create(to, ro, NULL);
			//
			ttf->runAction(se);
		}
		return false;
	};

	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, ttf);

 

		//Director::getInstance()->replaceScene(GameScene::createScene());//切换到下一个场景,并关闭本场景
 		//Director::getInstance()->pushScene(HelpScene::createScene());//切换到下一场景,但不关闭本场景
		//Director::getInstance()->popScene();//关闭本场景



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值