cocos2d-x CCAnimate获取当前帧

cocos2d的CCAnimate本身没有获取当前是第几帧的函数,网上看了几个获取当前帧的方法感觉都不对,就自己写了一个

int CCAnimate::getCurFrameIndex()
{
    CCMutableArray<CCSpriteFrame*> *pFrames = m_pAnimation->getFrames();
    unsigned int numberOfFrames = pFrames->count();
    
    int currentFrame = 0;
    
    CCSprite *pSprite = (CCSprite*)(m_pTarget);
    if (pSprite!=NULL) {
        for(int i = 0; i < numberOfFrames; i++){
            if(pSprite->isFrameDisplayed(pFrames->getObjectAtIndex(i)))
            {
                currentFrame=i;
                break;
            }
        }
    }
    
    return currentFrame;
}


你可能感兴趣的:(cocos2d-x)