Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2dx学习笔记2大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

1. 运动类

(1)移动,拉伸,闪烁,重复动作

	MoveTo* moveTo = MoveTo::create(0.9f,Point(250,150));
<span style="white-space:pre">	</span>MoveBy* moveBy = MoveBy::create(0.9f,Point(100,100));
	sprite->runAction(moveTo);
ScaleTo scaleTo = ScaleTo::create(0.9f,0.4f,10.f);
ScaleBy scaleBy = ScaleBu::create(0.9f,1.0f)
	Blink* blink = Blink::create(3.0f,5);
	JumpBy* jumpBy = JumpBy::create(3.0f,Point(50,1),100,1);
	RepeatForever* RepeatForeverAction = RepeatForever::create(jumpBy);
	//Repeat* RepeatAction = Repeat::create(jumpBy,5);
	sprite->runAction(jumpBy);
	Action* action = Spawn::create(moveTo,jumpBy,scaleTo,null);//几个动作同时做
	Action* action = Sequence::create(moveTo,null);//一个接一个动作
2.动作监听,请看代码
	MoveTo* moveHome = MoveTo::create(10.0f,100));
	auto callBACkFunc[&]()
	{
		log("I fine");
	};
	CallFunc* callFunc = CallFunc::create(callBACkFunc);
	Action* actions = Sequence::create(moveHome,callFunc,null); 
	sprite->runAction(actions);

3.屏幕触摸事件

	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [](Touch* touch,Event* event)//手指按下时
	{
		Point pos1 = touch->getLOCATIOn();//基于3D
		Point pos2 = touch->getLOCATIOnInView();//基于2D,左上角为原点
		Point pos3 = Director::geTinstance()->convertToGL(pos2);//右下角为原点,笛卡尔坐标,常用的就是这种方式!!!!
		log("pos1 x = %f,y = %f,",pos1.x,pos1.y);
		log("pos1 x = %f,pos2.x,pos2.y);
		log("pos1 x = %f,pos3.x,pos3.y);
		return true;
	};
	listener->onTouchMoved = [](Touch* touch,Event* event)//手指在屏幕拖动时会一直调用
	{
		log("moved");
	};
	listener->onTouchEnded = [](Touch* touch,Event* event)//手指松开时
	{
		log("end");
	};
	_eventDispatcher->addEventListenerWithSceneGraphpriority(listener,this);//事件管理器注册监听listener
三个事件,另外一个onTouchCancelled 打断触摸事件,是系统级的消息,如手机来电就会被中断。

4.多点触摸

auto listener = EventListenerTouchAllAtOnce  ::create();
listener->setSwallowTouches(true);//吞没事件,当某个触摸事件回调时,截断这个事件,不让他继续往下传
	listener->onTouchBegan = [](const std::vector<Touch*> &touches,Event* event){};
	listener->onTouchMoved = [](const std::vector<Touch*> &touches,Event* event)
	{
		int num = touches.size();
		for(auto &touch : touches)
		{
			auto LOCATIOn = touch->getLOCATIOn();
		}
	};
	listener->onTouchEnded = [](const std::vector<Touch*> &touches,Event* event)
	{
		auto target = static_cast<Sprite*>(event->getCurrentTarget());//这个只有在监听事件时绑定对象才有效,将最后一句中的this改为绑定的对象。
		....
	};
	_eventDispatcher->addEventListenerWithSceneGraphpriority(listener,this);
</pre><pre name="code" class="cpp">
<pre name="code" class="cpp">5.Cocos2dx微信分享


5.微信分享博文链接

http://www.cocoachina.com/bbs/read.php?tid-224616-page-1.html
http://www.cocoachina.com/bbs/simple/?t50484.html
<pre name="code" class="cpp">http://blog.sina.com.cn/s/blog_92ac2c5b0101dgru.html

大佬总结

以上是大佬教程为你收集整理的cocos2dx学习笔记2全部内容,希望文章能够帮你解决cocos2dx学习笔记2所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。