上次说到,当点击一个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开发整理发布,转载须标明出处。。