上次说到,当点击一个menu时,会创建一个新的test,并调用它的runThisTest方法,比如actionTest
voID ActionsTestScene::runThistest(){ s_nActionIDx = -1; addChild(NextAction()); CCDirector::sharedDirector()->replaceScene(this); }
每一个test都继承自TestScene,TestScene又继承自CCScene,这里TestScene做了一下初始化工作,在构造函数里设置了屏幕为横屏并调用 CCScene::init()方法来设置场景的大小为窗口大小
,在onEnter方法里创建了一个用于返回到主界面的按钮。
addChild(NextAction());中NextAction()方法创建了一个新的layer用于演示action比如ActionManual,注意这里所有的layer都继承自ActionsDemo,ActionsDemo继承自cclayer。当我们创建ActionManual时,它会首先调用ActionsDemo::onEnter();这里对主界面进行了初始化,初始化了三个sprite、三个menu,两个label。
然后回到ActionManual::onEnter(),这里对上述三个sprite进行了缩放,旋转,透明,变化颜色,变化位置的 *** 作。
下面的都类似,只是action不同
cclayer* CreateLayer(int nIndex) { cclayer * pLayer = NulL; switch (nIndex) { case ACTION_MANUAL_LAYER: pLayer = new ActionManual(); break; case ACTION_MOVE_LAYER: pLayer = new ActionMove(); break;//移动sprite case ACTION_SCALE_LAYER: pLayer = new ActionScale(); break;//缩放sprite case ACTION_ROTATE_LAYER: pLayer = new ActionRotate(); break;//旋转sprite case ACTION_SKEW_LAYER: pLayer = new ActionSkew(); break;//倾斜sprite case ACTION_SKEWROTATE_LAYER: pLayer = new ActionSkewRotateScale(); break;//m_tamara->removeFromParentAndCleanup(true);这个方法可以从父类中移除自己。还有并发action不是得用CCSpawn吗?难道不需要?? case ACTION_JUMP_LAYER: pLayer = new ActionJump(); break;//actionTo和actionBy的区别:前者是跳到这个坐标点,后者是基于原来的位置跳多少距离,比如actionBy(ccp(0,0))就是在原地跳 case ACTION_BEZIER_LAYER:、、 pLayer = new ActionBezIEr(); break;//贝尔曲线 case ACTION_Blink_LAYER: pLayer = new ActionBlink(); break;//闪烁 case ACTION_FADE_LAYER: pLayer = new ActionFade(); break;//淡入淡出 case ACTION_TINT_LAYER: pLayer = new ActionTint(); break;//从一种颜色变为另一种 case ACTION_ANIMATE_LAYER: pLayer = new ActionAnimate(); break;//动画 case ACTION_SEQUENCE_LAYER: pLayer = new ActionSequence(); break;//按顺序执行一系列动作 case ACTION_SEQUENCE2_LAYER: pLayer = new ActionSequence2(); break;//action结束可以回调某个方法 case ACTION_SPAWN_LAYER: pLayer = new ActionSpawn(); break;//并发,就是多个动作同时进行 case ACTION_REVERSE: pLayer = new ActionReverse(); break;//执行相反动作 case ACTION_DELAYTIME_LAYER: pLayer = new ActionDelayTime(); break;// CCSequence::actions( move,CCDelayTime::actionWithDuration(2),move,NulL);CCDelayTime::actionWithDuration(2)可以执行延时 case ACTION_REPEAT_LAYER: pLayer = new ActionRepeat(); break;// case ACTION_REPEATEFOREVER_LAYER: pLayer = new ActionRepeatForever(); break;// case ACTION_ROTATetoREPEATE_LAYER: pLayer = new ActionRotatetoRepeat(); break; case ACTION_ROTATEJERK_LAYER: pLayer = new ActionRotateJerk(); break; case ACTION_CALLFUNC_LAYER: pLayer = new ActionCallFunc(); break; case ACTION_CALLFUNCND_LAYER: pLayer = new ActionCallFuncND(); break; case ACTION_REVERSESEQUENCE_LAYER: pLayer = new ActionReverseSequence(); break; case ACTION_REVERSESEQUENCE2_LAYER: pLayer = new ActionReverseSequence2(); break; case ACTION_ORBIT_LAYER: pLayer = new Actionorbit(); break;//每一个CCNode对象都有一个Camera,默认的位置是锚点?所以我们看到的2D图都是规则的,当我们改变Camera的位置时,就会看到这个CCNode对象的不同形状,不知道这样理解对不对 case ACTION_FLLOW_LAYER: pLayer = new ActionFollow(); break; default: break; } return pLayer;}
原文地址:http://www.itmmd.com/201410/70.html
该文章由android开发整理发布,转载须标明出处。。
以上是内存溢出为你收集整理的cocos2d-x Tests教程:ActionsTest 详解全部内容,希望文章能够帮你解决cocos2d-x Tests教程:ActionsTest 详解所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)