现在的位置: 首页 > 综合 > 正文

天龙源码分析 – cegui 实现表情

2012年08月06日 ⁄ 综合 ⁄ 共 2269字 ⁄ 字号 评论关闭

一 AnimateManager

表情管理类,保存了所有表情Animate

        typedef std::map< String, Animate* > AnimateNameRegistry;
        
//All animate
        AnimateNameRegistry d_animateNameMap;

        typedef std::map< int, Animate* > AnimateIDRegistry;
        
//Animate use id as index.
        AnimateIDRegistry d_animateIDMap;

 

 

二 Animate

代表一个表情,比如笑脸,包含一组笑脸的图片

        struct AnimateKey
        {
            
const Image* d_image;
        };
        typedef std::vector
< AnimateKey >  AnimateKeyRegistry;

 

 

其中一个比较重要的函数是

        /*!
        \brief
        Get the frame use species time and time total.

        \param time_now
        Specifies the time current.

        \param time_total
        Specifies the total time length.

        \return 
        The frame image that at the time. If the animate should stop or not start yet, return 0.
        */
        
const Image* getFrame(int time_elapsed, int time_total) const;

 

 

能够根据实际便宜值,求对应的图片

另外一个函数

 

float Animate::getFrameAlpha( int time_elapsed, int time_total )
{
    
if( time_total == -1 ) 
        time_total 
= d_totalTime;
    
if( d_bModeAlpha == false )
        
return 1;
    
int nTime = time_elapsed;
    
if( d_loopMode )
        nTime 
= time_elapsed % time_total;

    float alpha    = float( nTime ) / float( time_total );
    
switch( d_loopType )
    {
    
case 0// 0 -- 255
        break;
    
case 1// 0 -- 255 -- 0
        {
            
if( alpha < 0.5 )
                alpha 
*= 2;
            
else
                alpha 
= ( 1.0f - alpha ) * 2;
        }
        
break;
    
case 2// 255 -- 0
        alpha = 1 - alpha;
        
break;
    }
    
return alpha;

}

 

可以更新表情的alpha

三 FalagardAnimate

具体使用表情的控件,包含了Animate的指针

其中一个比较重要的函数是

    void    FalagardAnimate::updateSelf(float elapsed)
    {
        
// 得到相应得播放了得时间
        if( m_pAnimate  )
        {
            
if( m_bPlay )
            {
                
int time_now = (int)(System::getSingleton().getCurTimeElapsed()*1000.0f);
                
const Image* pFrame = m_pAnimate->getFrame( time_now - m_nAnimateStart, -1 );
                m_fAlpha 
= m_pAnimate->getFrameAlpha( time_now - m_nAnimateStart, -1 );
                d_normalImage.setImage( pFrame ) ;
            }
            
else
            {
                d_normalImage.setImage( NULL ) ;
            }
            
            requestRedraw();
        }
        
    }

 

这个函数就可以更新图片了

抱歉!评论已关闭.