Cocos2D3.x学习笔记之ActionManagerTest

Cocos2D3.x学习笔记之ActionManagerTest,第1张

概述今天看了,ActionManagerTest的例子,做一下总结。 这里面总共有6个Test,都比较简单,介绍了一些ActionManager的功能。 1.CrashTest 崩溃测试,这个测试是来测试崩溃的,在这个测试中用到的例子是为一个节点添加两个同样时长的Action,为这个节点的父节点也添加一个这样的Action,程序能够正常的运行,没有崩溃,说明引擎是支持这样的 *** 作的。 2.LogicTe

今天看了,ActionManagerTest的例子,做一下总结。

这里面总共有6个Test,都比较简单,介绍了一些ActionManager的功能。

1.CrashTest

崩溃测试,这个测试是来测试崩溃的,在这个测试中用到的例子是为一个节点添加两个同样时长的Action,为这个节点的父节点也添加一个这样的Action,程序能够正常的运行,没有崩溃,说明引擎是支持这样的 *** 作的。

2.LogicTest

逻辑 *** 作,这个测试解释的是一个逻辑问题,当一个节点执行过一次stopAllActions的 *** 作后,再次执行是没有任何作用的,当然,前提是两次调用之间没有添加新的动作。

3.StopAllActionTest

这个也是一个停止动作的测试,不过这个测试有一点不同是,根据多做的Tag来停止动作,节点的其他动作不受影响。这个功能的用途应该是很广泛的,在实际应用中可以直接照搬这种方法,给需要停止的动作添加Tag,不需要的时候直接停止就好了,需要的时候再resume。

4.ResumeTest

重启测试,这个是在一个动作停止后,重启动作的一个测试。用到了Schedule重启动作。也是一个很有用的例子。我们可以为节点的动作加上Tag,需要那个动作就resume哪个动作,当然,到底需要启动那个动作应该是根据项目来决定的,大部分时候应该是有一个状态机来控制的。

5.StopTest

停止测试,这个特殊之处在于,在一个sequence中的自动作中停止整个sequence动作。引擎是允许这样的 *** 作的,不崩溃。

6.PauseTest

暂停测试,这个测试是我感觉这几个测试中限制最多的测试,虽然,我还不知道为什么有这么多限制。做这个 *** 作,必须在onEnter函数中进行,不能够在init函数中进行,除非被暂停的action是在‘onEnter’的时候启动,这个限制还是很苛刻的。

下面总结一些在这个Test中感觉有用的代码:

1.CrashTest

   1: runAction( Sequence::create(
   2:                                  DelayTime::create(1.5f),
   3:                                  CallFunc::create( CC_CALLBACK_0(CrashTest::removeThis,this)),
   4:                                  nullptr)
   5:           );
   6:  
   7: voID CrashTest::removeThis()
   8: {
   9:     _parent->removeChild(this,true);
  10:     
  11:     nextCallback(this);
  12: }

//这段代码中有sequence的用法,CallFunc的用法,他们的用法与2.x的版本差异还是挺大的。

2.LogicTest

1: grossini->runAction( Sequence::create(
   2:                                                 MoveBy::create(1,Vec2(150,0)),monospace; direction:ltr; border-top-style:none; color:black; border-right-style:none; Font-size:8pt; overflow:visible; padding-top:0px">   3:                                                 CallFuncN::create(CC_CALLBACK_1(LogicTest::BUGMe,monospace; direction:ltr; border-top-style:none; color:black; border-right-style:none; Font-size:8pt; overflow:visible; padding-top:0px">   4:                                                 nullptr) 
   5:                         );
   6: voID LogicTest::BUGMe(Node* node)
   7: {
   8:     node->stopAllActions(); //After this stop next action not working,if remove this stop everything is working
   9:     node->runAction(Scaleto::create(2,2));
  10: }
//这段代码中有CallFuncN的另一种用法。

3.PauseTest

这个代码保留全部,以后用到这个功能直接来找就OK了。

1: voID PauseTest::onEnter()
   2: {
   3:     //
   4:     // This test MUST be done in 'onEnter' and not on 'init'
   5:     // otherwise the paused action will be resumed at 'onEnter' time
   6:     //
   7:     ActionManagerTest::onEnter();
   8:     
   9: 
  10:     auto l = Label::createWithTTF("After 5 seconds grossini should move","Fonts/Thonburi.ttf",16.0f);
  11:     addChild(l);
  12:     l->setposition(VisibleRect::center().x,VisibleRect::top().y-75);
  13:     
  14:     
  15:     //
  16:     // Also,this test MUST be done,after [super onEnter]
  17:     //
  18:     auto grossini = Sprite::create(s_pathGrossini);
  19:     addChild(grossini,kTagGrossini);
  20:     grossini->setposition(VisibleRect::center() );
  21:     
  22:     auto action = MoveBy::create(1,0));
  23: 
  24:     auto director = Director::getInstance();
  25:     director->getActionManager()->addAction(action,grossini,monospace; direction:ltr; border-top-style:none; color:black; border-right-style:none; Font-size:8pt; overflow:visible; padding-top:0px">  26: 
  27:     schedule( CC_SCHEDulE_SELECTOR(PauseTest::unpause),3); 
  28: }
  29: 
  30: voID PauseTest::unpause(float dt)
  31: {
  32:     unschedule( CC_SCHEDulE_SELECTOR(PauseTest::unpause) );
@H_293_301@  33:     auto node = getChildByTag( kTagGrossini );
  34:     auto director = Director::getInstance();
  35:     director->getActionManager()->resuMetarget(node);
  36: }

4.StopTest,StopAllActionTest

保留实现功能的两段代码。

1: auto sprite = getChildByTag(kTagGrossini);
   2:     sprite->stopActionByTag(kTagsequence);
   3: 
   4: auto sprite = getChildByTag(kTagGrossini);
   5:     sprite->stopAllActionsByTag(kTagsequence);

5.ResumeTest

保留实现功能的代码。

1: voID ResumeTest::onEnter()
   3:     ActionManagerTest::onEnter();
   4: 
   5:     auto l = Label::createWithTTF("Grossini only rotate/scale in 3 seconds",16.0f);
   6:     addChild(l);
   7:     l->setposition(VisibleRect::center().x,VisibleRect::top().y - 75);
   8: 
   9:     auto pGrossini = Sprite::create(s_pathGrossini);
  10:     addChild(pGrossini,kTagGrossini);
  11:     pGrossini->setposition(VisibleRect::center());
  12: 
  13:     pGrossini->runAction(ScaleBy::create(2,monospace; direction:ltr; border-top-style:none; color:black; border-right-style:none; Font-size:8pt; overflow:visible; padding-top:0px">  14: 
  15:     auto director = Director::getInstance();
  16:     director->getActionManager()->pauseTarget(pGrossini);
  17:     pGrossini->runAction(RotateBy::create(2,360));
  18: 
  19:     this->schedule(CC_SCHEDulE_SELECTOR(ResumeTest::resumeGrossini),3.0f);
  20: }
  21: 
  22: voID ResumeTest::resumeGrossini(float time)
  23: {
  24:     this->unschedule(CC_SCHEDulE_SELECTOR(ResumeTest::resumeGrossini));
  25: 
  26:     auto pGrossini = getChildByTag(kTagGrossini);
  27:     auto director = Director::getInstance();
  28:     director->getActionManager()->resuMetarget(pGrossini);
  29: }
总结

以上是内存溢出为你收集整理的Cocos2D3.x学习笔记之ActionManagerTest全部内容,希望文章能够帮你解决Cocos2D3.x学习笔记之ActionManagerTest所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1045230.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存