46 lines
		
	
	
		
			787 B
		
	
	
	
		
			C++
		
	
	
	
		
		
			
		
	
	
			46 lines
		
	
	
		
			787 B
		
	
	
	
		
			C++
		
	
	
	
|  | #include "..\easy2d.h"
 | |||
|  | #include "..\Win\winbase.h"
 | |||
|  | 
 | |||
|  | Animation::Animation(float duration) | |||
|  | { | |||
|  | 	m_nDuration = 0; | |||
|  | 	m_nTotalDuration = UINT(duration * 1000); | |||
|  | } | |||
|  | 
 | |||
|  | Animation::~Animation() | |||
|  | { | |||
|  | } | |||
|  | 
 | |||
|  | bool Animation::_isEnd() const | |||
|  | { | |||
|  | 	return m_nDuration >= m_nTotalDuration; | |||
|  | } | |||
|  | 
 | |||
|  | void Animation::_init() | |||
|  | { | |||
|  | 	Action::_init(); | |||
|  | 	// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
 | |||
|  | 	m_nLast = steady_clock::now(); | |||
|  | } | |||
|  | 
 | |||
|  | bool Animation::_isDelayEnough(steady_clock::time_point nNow) | |||
|  | { | |||
|  | 	// <20>ж<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>㹻
 | |||
|  | 	if (duration_cast<milliseconds>(nNow - m_nLast).count() > m_nAnimationInterval) | |||
|  | 	{ | |||
|  | 		// <20><><EFBFBD>¼<EFBFBD>¼ʱ<C2BC><CAB1>
 | |||
|  | 		m_nLast += milliseconds(m_nAnimationInterval); | |||
|  | 		m_nDuration += m_nAnimationInterval; | |||
|  | 		return true; | |||
|  | 	} | |||
|  | 	return false; | |||
|  | } | |||
|  | 
 | |||
|  | void Animation::_reset() | |||
|  | { | |||
|  | 	Action::_reset(); | |||
|  | 	m_nDuration = 0; | |||
|  | 	// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
 | |||
|  | 	m_nLast = steady_clock::now(); | |||
|  | } |