1. 运动类
(1)移动,拉伸,闪烁,重复动作
Moveto* moveto = Moveto::create(0.9f,Point(250,150));<span > </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" >
<pre name="code" >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" >http://blog.sina.com.cn/s/blog_92ac2c5b0101dgru.HTML总结
以上是内存溢出为你收集整理的cocos2dx学习笔记2全部内容,希望文章能够帮你解决cocos2dx学习笔记2所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)