码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx3.2 学习笔记(2)--ActionManagerTest

时间:2017-05-16 14:57:18      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:完整   ssi   基本   use   stop   after   ati   cpp   tar   

       前面看完了 CppTests的基本框架及流程。如今准备看看详细的每一个Test了

       从哪里開始看呢。

额,就第一个吧(ActionManagerTest)

 

       首先看看效果吧,执行了下。发现有几种效果。看不出什么名堂,感觉有点奇怪。

打开代码先看看头文件,发现原来不是一个类 ,是几个类都放在了这里,都是ActionManagerTest的 预计就是几种效果吧,方法也都没几个。不难发现,基本前面两个方法都一

样。仅仅有第三个方法不一样。

去cpp文件看看情况,先定义了一个枚举,不知道干嘛的,然后是声明了三个函数,看名字大概猜到是什么了。

直接贴代码打凝视好了

Layer* nextActionManagerAction();  --下一个动作
Layer* backActionManagerAction(); --上一个动作
Layer* restartActionManagerAction();--重置动作

static int sceneIdx = -1;    然后是定义了一个索引

#define MAX_LAYER    5 定义了最大层数

依据索引创建详细的layer

Layer* createActionManagerLayer(int nIndex) 
{

  //我学的时候直接在这里返回某个详细layer,一个个看究竟什么效果return new CrashTest();
    switch(nIndex)
    {
        case 0: return new CrashTest();
        case 1: return new LogicTest();
        case 2: return new PauseTest();
        case 3: return new StopActionTest();
        case 4: return new ResumeTest();
    }

    return nullptr;
}

下一个动作button回调,改变索引

Layer* nextActionManagerAction()
{
    sceneIdx++;
    sceneIdx = sceneIdx % MAX_LAYER;

    auto layer = createActionManagerLayer(sceneIdx);
    layer->autorelease();

    return layer;
}

上一个动作button回调,改变索引

Layer* backActionManagerAction()
{
    sceneIdx--;
    int total = MAX_LAYER;
    if( sceneIdx < 0 )
        sceneIdx += total;   
   
    auto layer = createActionManagerLayer(sceneIdx);
    layer->autorelease();

    return layer;
}

重置当前动作

Layer* restartActionManagerAction()
{
    auto layer = createActionManagerLayer(sceneIdx);
    layer->autorelease();

    return layer;
}

 

相同。 我首先看到是第一个CrashTest();

    auto child = Sprite::create(s_pathGrossini); //创建一张精灵
    child->setPosition( VisibleRect::center() ); //设置到中间
    addChild(child, 1);//加入到当前layer

    //Sum of all action‘s duration is 1.5 second.
    child->runAction(RotateBy::create(1.5f, 90)); //RotateBy这个函数从名字上能够了解到 是做旋转。(1.5秒内旋转90度)
    child->runAction(Sequence::create(                            //Sequence这个函数一下子没看明确,英文意思是动作序列,那应该是一个个动作
                                            DelayTime::create(1.4f),     //先是一个等待动作1.4秒
                                            FadeOut::create(1.1f),       //1.1秒淡入
                                            nullptr)
                    );
   
    //After 1.5 second, self will be removed.
    runAction( Sequence::create(
                                    DelayTime::create(1.4f),          //先是一个等待动作1.4秒 
                                    CallFunc::create( CC_CALLBACK_0(CrashTest::removeThis,this)),//运行一个回调
                                    nullptr)

看代码我以为是 一张精灵旋转90度后,等待1.4秒 然后淡入。然后等待1.4秒。然后运行回调

结果事实并非这种,我把代码凝视掉 一个个动作运行。后来发现 三个runAction是一起运行的

也就是先1.5秒的旋转同一时候在1.4秒的等待,到了1.5秒的时候,应该买没旋转到90度,然后要运行淡入了。也发现要运行回调了,结果直接就运行到了回调

说明动作是同一时候运行的,而且会打断上一个动作。我认为演示样例代码能够把第三个runAction 的等待时间改成2.5秒  这样就能够看到一个完整过程了。第二个runAction,已经能够看出动作会别打断的效果了。

应该是我没看懂作者的原意。

就剩下个回调了removeThis

void CrashTest::removeThis()
{
    _parent->removeChild(this, true); --把自己删除掉
   
    nextCallback(this); --创建下一个layer
}

 

cocos2dx3.2 学习笔记(2)--ActionManagerTest

标签:完整   ssi   基本   use   stop   after   ati   cpp   tar   

原文地址:http://www.cnblogs.com/slgkaifa/p/6860755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!