zoukankan      html  css  js  c++  java
  • spineRunTime for cocos2dx v3 中动画播完删除animation

    spineRunTime for cocos2dx v3 中删除animation,发现下面写法会崩溃:  

        spine::SkeletonAnimation* animationNode = spine::SkeletonAnimation::createWithFile("explosion/explosion.json", "explosion/explosion.atlas", 1);

            animationNode->setAnimation(0, "animation", false);

            animationNode->setPosition(ccp(x,y));

        animationNode->setEndListener( [animationNode] (int trackIndex) {

         //spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);

                //const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;

                //string animationName=t_animationName==0?"":t_animationName;

                //CCLOG("%d end: %s", trackIndex, animationName.c_str());

                animationNode->removeFromParentAndCleanup(true);

            });

    于是只好通过加一个延迟来避免崩溃,下面是可用的写法:

       spine::SkeletonAnimation* animationNode = spine::SkeletonAnimation::createWithFile("explosion/explosion.json", "explosion/explosion.atlas", 1);

            animationNode->setAnimation(0, "animation", false);

            animationNode->setPosition(ccp(x,y));

        animationNode->setEndListener( [animationNode] (int trackIndex) {

         //spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);

                //const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;

                //string animationName=t_animationName==0?"":t_animationName;

                //CCLOG("%d end: %s", trackIndex, animationName.c_str());

                animationNode->runAction(CCSequence::create(CCDelayTime::create(0.01),CCRemoveSelf::create(),NULL));

            });

    或者用completeListener,仍然需要加延迟:

      animationNode->setCompleteListener( [animationNode] (int trackIndex, int loopCount) {

                //spTrackEntry* entry = spAnimationState_getCurrent(animationNode->getState(), trackIndex);

                //const char* t_animationName = (entry && entry->animation) ? entry->animation->name : 0;

                //string animationName=t_animationName==0?"":t_animationName;

                //CCLOG("%d complete: %s %d", trackIndex, animationName.c_str(),loopCount);

                animationNode->runAction(CCSequence::create(CCDelayTime::create(0.01),CCRemoveSelf::create(),NULL));

                

            });

  • 相关阅读:
    [转载]安装SQL Server 2008 R2遇到“...Setup has stopped working.”
    WPF验证错误显示
    说一下我对Mvvm模式的理解
    [转载]C#深拷贝的方法
    Windows Phone 开发(一):入门指南 — 安装开发环境:Windows Phone SDK
    DateTime.ToString() Patterns
    Log4net 根据日志类别保存到不同的文件,并按照日期生成不同文件名称
    使用Visual Studio 2010进行UI自动化测试
    WPF触发器之数据触发器(A)
    Getting The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight for Phone\v4.0\Microsoft.Silverlight..Overrides.targets" was not found
  • 原文地址:https://www.cnblogs.com/wantnon/p/4483112.html
Copyright © 2011-2022 走看看