【问题标题】:loading animation through texturepacker in cocos2dx for windows phone通过 cocos2dx for windows phone 中的 texturepacker 加载动画
【发布时间】:2013-07-17 07:11:20
【问题描述】:

我正在使用以下代码运行动画

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("kid1.plist");


        CCSpriteBatchNode *spritesheet = CCSpriteBatchNode::create("kid1.png");
        this->addChild(spritesheet);

        CCArray *kidframes = new CCArray;
        for(int i=1; i<3; i++){
            CCString *filename = CCString::createWithFormat("kid%d.png",i);
            CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString());
            kidframes->addObject(frame);
        }

        CCAnimation *runanim = CCAnimation::createWithSpriteFrames(kidframes, 0.1);
        CCSprite *kiddo = CCSprite::createWithSpriteFrameName("kid2.png");

        kiddo->setPositionX(100*setScreenX);
        kiddo->setPositionY(100*setScreenY);
        kiddo->setScaleX(setScreenX);
        kiddo->setScaleY(setScreenY);

        CCAction *action = CCRepeatForever::create(CCAnimate::create(runanim));
        kiddo->runAction(action);
        spritesheet->addChild(kiddo);

当我将框架添加到儿童框架时,这不起作用它给我一个错误 CCAssert(m_uReference > 0, "引用计数应大于 0"); 有什么帮助吗?

【问题讨论】:

    标签: animation windows-phone cocos2d-x texturepacker


    【解决方案1】:

    这是我们用来为 Sprite 设置动画的东西。

    CCAnimation *animation = CCAnimation::create();
    animation->setDelayPerUnit(0.05f);
    
    //Add the frames to the animation
    string animationFramePrefix = "mySprite";
    string  animationFrames = "1,2,3,4,5,6,7,8,9";
    
    char *strArr=new char[animationFrames.size()+1];
    strArr[animationFrames.size()]=0;
    memcpy(strArr,animationFrames.c_str(),animationFrames.size());
    
    const char* p;
    for (p = strtok(strArr, "," );  p;  p = strtok( NULL, "," ))
    {
        string frameName = animationFramePrefix+"_"+p+".png";
        CCSpriteFrame* sprite =  CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName.c_str());
        animation->addSpriteFrame(sprite);
    }
    
    //initialize sprite with initial display frame
    CCSprite *mySprite = CCSprite::createWithSpriteFrameName("mySprite_1.png");
    
    //then use the animation when required!
    CCAnimate *animationAction = CCAnimate::create(animation);
    CCRepeatForever *repeatAction = CCRepeatForever::create(animationAction);
    mySprite->runAction(repeatAction);
    

    【讨论】:

      【解决方案2】:

      尝试改变

      CCArray *kidframes = new CCArray;
      

      CCArray *kidframes = CCArray::create();
      

      【讨论】:

      • 我再次添加了 plist 文件,它现在没有显示错误,但它的作用是它启动了游戏,但是当动画必须启动时游戏才关闭:/
      【解决方案3】:

      而不是new ccarray();

      试试create::ccarray();

      【讨论】:

        猜你喜欢
        • 2012-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多