void CCAnimationCache::parseVersion1(CCDictionary* animations)
{
    CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();

    CCDictElement* pElement = NULL;
    CCDICT_FOREACH(animations, pElement)
    {
        CCDictionary* animationDict = (CCDictionary*)pElement->getObject();
        CCArray* frameNames = (CCArray*)animationDict->objectForKey("frames");
        float delay = animationDict->valueForKey("delay")->floatValue();
        CCAnimation* animation = NULL;

        if ( frameNames == NULL ) 
        {
            CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey());
            continue;
        }

        CCArray* frames = CCArray::createWithCapacity(frameNames->count());
        frames->retain();

        CCObject* pObj = NULL;
        CCARRAY_FOREACH(frameNames, pObj)
        {
            const char* frameName = ((CCString*)pObj)->getCString();
            CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName);

            if ( ! spriteFrame ) {
                CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName);

                continue;
            }

            CCAnimationFrame* animFrame = new CCAnimationFrame();
            animFrame->initWithSpriteFrame(spriteFrame, 1, NULL);
            frames->addObject(animFrame);
            animFrame->release();
        }

        if ( frames->count() == 0 ) {
            CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey());
            continue;
        } else if ( frames->count() != frameNames->count() ) {
            CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey());
        }

        animation = CCAnimation::create(frames, delay, 1);

        CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pElement->getStrKey());
        frames->release();
    }    
Example #2
0
CCAnimate* Image::getFullAnimation(float delay, bool invert)
{
    CCAssert(spriteSheet != NULL, "Image getFullAnimation called on an object without spritesheet");
    CCArray* animationFrames = CCArray::createWithCapacity(spritesName->count());
    for(int i = 0; i < spritesName->count(); i++)
    {
        CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(invert ? spritesName->count() - i - 1 : i))->getCString());
        CCAnimationFrame* frame = new CCAnimationFrame();
        frame->initWithSpriteFrame(spriteFrame, 1, NULL);
        frame->autorelease();
        animationFrames->addObject(frame);
    }
    return CCAnimate::create(CCAnimation::create(animationFrames, delay));
}
Example #3
0
CCObject* CCAnimationFrame::copyWithZone(CCZone* pZone)
{
    CCZone* pNewZone = NULL;
    CCAnimationFrame* pCopy = NULL;
    if(pZone && pZone->m_pCopyObject) 
    {
        //in case of being called at sub class
        pCopy = (CCAnimationFrame*)(pZone->m_pCopyObject);
    }
    else
    {
        pCopy = new CCAnimationFrame();
        pZone = pNewZone = new CCZone(pCopy);
    }

    pCopy->initWithSpriteFrame((CCSpriteFrame*)m_pSpriteFrame->copy()->autorelease(),
        m_fDelayUnits, m_pUserInfo != NULL ? (CCDictionary*)m_pUserInfo->copy()->autorelease() : NULL);

    CC_SAFE_DELETE(pNewZone);
    return pCopy;
}
Example #4
0
bool CCAnimation::initWithSpriteFrames(CCArray *pFrames, float delay)
{
    CCARRAY_VERIFY_TYPE(pFrames, CCSpriteFrame*);

    m_uLoops = 1;
    m_fDelayPerUnit = delay;
    CCArray* pTmpFrames = CCArray::array();
    setFrames(pTmpFrames);

    if (pFrames != NULL)
    {
        CCObject* pObj = NULL;
        CCARRAY_FOREACH(pFrames, pObj)
        {
            CCSpriteFrame* frame = (CCSpriteFrame*)pObj;
            CCAnimationFrame *animFrame = new CCAnimationFrame();
            animFrame->initWithSpriteFrame(frame, 1, NULL);
            m_pFrames->addObject(animFrame);
            animFrame->release();

            m_fTotalDelayUnits++;
        }
Example #5
0
void Image::runFullAnimation(float delay, bool invert)
{
    CCAssert(spriteSheet != NULL, "Image runFullAnimation called on an object without spritesheet");
    CCArray* animationFrames = CCArray::createWithCapacity(spritesName->count());
    for(int i = 0; i < spritesName->count(); i++)
    {
        CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(invert ? spritesName->count() - i - 1 : i))->getCString());
        CCAnimationFrame* frame = new CCAnimationFrame();
        frame->initWithSpriteFrame(spriteFrame, 1, NULL);
        frame->autorelease();
        animationFrames->addObject(frame);
    }
    CCAction* action = CCRepeatForever::create(CCAnimate::create(CCAnimation::create(animationFrames, delay)));
    if(runningAnimation != action)
    {
        if(runningAnimation != NULL)
        {
            delegate->stopAction(runningAnimation);
        }
        delegate->runAction(action);
        runningAnimation = action;
    }
}