Ejemplo n.º 1
0
void Character::dealloc()
{
    CC_SAFE_RELEASE_NULL(_cached_shadow_scaleLoop);
    CC_SAFE_RELEASE_NULL(_cached_shadow_scaleToSmallerThenNormalOneTime);
    CC_SAFE_RELEASE_NULL(_cached_shadow_scaleToBiggerThenNormalOneTime);
    CC_SAFE_RELEASE_NULL(_cached_shadow_scaleToNormalOneTime);
    CC_SAFE_RELEASE_NULL(_cached_shadow_scaleForMidAirThenNormalOneTime);
    
    // clear out displayed-frame-cmds
    if(m_managedDisplayedFrameCMDs)
    {
        for(int i=0; i<m_managedDisplayedFrameCMDs->count(); i++)
        {
            CCAnimationFrame *frame = static_cast<CCAnimationFrame*>(m_managedDisplayedFrameCMDs->objectAtIndex(i));
            
            // clear out all data in dict
            frame->getUserInfo()->removeAllObjects();
            
            // set null to user info
            frame->setUserInfo(NULL);
        }
        
        m_managedDisplayedFrameCMDs->removeAllObjects();
        CC_SAFE_RELEASE_NULL(m_managedDisplayedFrameCMDs);
    }
    
    CC_SAFE_RELEASE_NULL(m_shadow);
}
//-------------------------------------------------------------------------
// 帧更新
void FKAnimateEx::Update( float dt )
{
	if( m_pAniRes == NULL )
		return;
	if( !m_pAniRes->IsValid() )
		return;
	if( m_pAniRes->IsValid() && !m_bIsResValid )
	{
		Play( m_szCurAniName, m_fSpeed, m_nLoopTime );
		m_bIsResValid = true;
	}

	if( m_pCurAnimation == NULL )
	{
		set<string>& AniNameSet = m_pAniRes->GetAniNameList();
		if( AniNameSet.empty() )
			return;

		set<string>::iterator IteBegin = AniNameSet.begin();
		Play( *IteBegin, m_fSpeed, m_nLoopTime );
		if( m_pCurAnimation == NULL )
			return;

		m_szCurAniName = (*IteBegin);
	}

	switch( m_eState )
	{
	case eAnimState_Normal:
		{
			float fDuration = m_pCurAnimation->getDuration();
			CCArray* pFrames = m_pCurAnimation->getFrames();
			int nFrames = static_cast<int>( pFrames->count() );
			float fLastTime = m_fTime;
			m_fTime += dt * m_fSpeed;
			
			if( m_fTime >= fDuration )
			{
				// 循环播放
				if( m_nLoopTime == -1 )
				{
					m_nNextFrame = 0;
					m_fTime = 0.0f;
				}
				else
				{
					m_nNextFrame = 0;
					m_fTime = 0.0f;
					m_nLoopTime--;
					if( m_nLoopTime == 0 )
					{
						m_eState = eAnimState_Stop;
						// 动作回调
						_OnAniCallback( fLastTime, m_fTime, fDuration );
						return;
					}
				}
			}

			CCSpriteFrame* pFrameToDisplay = NULL;
			for( int i = m_nNextFrame; i < nFrames; ++i )
			{
				float fSplitTime = m_vecFrameTimes.at( i );
				if( fSplitTime <= m_fTime )
				{
					CCAnimationFrame* pFrame = (CCAnimationFrame*)pFrames->objectAtIndex(i);
					pFrameToDisplay = pFrame->getSpriteFrame();
					((CCSprite*)m_pTarget)->setDisplayFrame( pFrameToDisplay );

					CCDictionary* pDict = pFrame->getUserInfo();
					if( pDict )
					{
						// 动作播放回调
					}
					m_nNextFrame = i + 1;
					break;
				}
			}

			// 动画回调
			_OnAniCallback( fLastTime, m_fTime, fDuration );
		}
		break;
	case eAnimState_Pause:
		break;
	case eAnimState_Stop:
		break;
	}
}