#include "animatedsprite.h" AnimatedSprite::AnimatedSprite() { }; AnimatedSprite::AnimatedSprite( char* texturefile, int numOfFrames, int cellWidth, int cellHeight, int numOfRows, int numOfColumns ) { _position = new D3DXVECTOR3(0, 0, 0); _velocity = new D3DXVECTOR3(0, 0, 0); _entType = tAnimatedSprite; gpKexan->gpEBank->AddToEntityList( this, _entType ); // _texture = gpKexan->gpTBank->AddTexture( texturefile ); gpKexan->gpTBank->AddTexture( texturefile ); _texture = gpKexan->gpTBank->GetTexture( texturefile )->_texture; m_TotalFrames = numOfFrames; m_CurrentFrame = 0; m_CellWidth = cellWidth; m_CellHeight = cellHeight; m_NumOfRows = numOfRows; m_NumOfColumns = numOfColumns; tickCount = 0; } void AnimatedSprite::SetCurrentFrame( int frame ) { m_CurrentFrame = frame; } int AnimatedSprite::GetWidth( void ) { return m_CellWidth; } int AnimatedSprite::GetHeight( void ) { return m_CellHeight; } void AnimatedSprite::Update() { BaseSprite::Update(); tickCount++; if( tickCount > 15 ) { m_CurrentFrame++; if( m_CurrentFrame >= m_TotalFrames ) { m_CurrentFrame = 0; } tickCount = 0; } } void AnimatedSprite::Draw() { RECT cellRect; cellRect.top = 0; cellRect.left = 0; int curFrame = m_CurrentFrame; while( curFrame >= m_NumOfColumns ) { cellRect.top += m_CellHeight; curFrame = curFrame - m_NumOfColumns; } while( curFrame > 0 ) { cellRect.left += m_CellWidth; curFrame--; } cellRect.bottom = cellRect.top + m_CellHeight; cellRect.right = cellRect.left + m_CellWidth; gpKexan->gpGEngine->_pSpriteHandler->Begin(D3DXSPRITE_ALPHABLEND); gpKexan->gpGEngine->_pSpriteHandler->Draw( _texture, &cellRect, NULL, _position, D3DCOLOR_XRGB(255,255,255)); gpKexan->gpGEngine->_pSpriteHandler->End(); }