| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | #include "..\eactions.h"
 | 
					
						
							|  |  |  |  | #include "..\Win\winbase.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | #include <typeinfo>
 | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | e2d::EAnimation::EAnimation() : | 
					
						
							|  |  |  |  | 	m_nFrameIndex(0) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	// ֡<><D6A1><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC> 0.1s ˢ<><CBA2>һ<EFBFBD><D2BB>
 | 
					
						
							|  |  |  |  | 	setInterval(100); | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | e2d::EAnimation::EAnimation(LONGLONG frameDelay) : | 
					
						
							|  |  |  |  | 	m_nFrameIndex(0) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	setInterval(frameDelay); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::EAnimation::~EAnimation() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 	for (auto frame = m_vFrames.begin(); frame != m_vFrames.end(); frame++) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 		SafeRelease(&(*frame)); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:47:36 +08:00
										 |  |  |  | void e2d::EAnimation::_init() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	EAction::_init(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  |  | void e2d::EAnimation::_update() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-08 15:37:52 +08:00
										 |  |  |  | 	EAction::_update(); | 
					
						
							| 
									
										
										
										
											2017-11-03 12:51:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	if (m_pTarget == nullptr) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->stop(); | 
					
						
							|  |  |  |  | 		return; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-03 12:51:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 	// <20>ж<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>㹻
 | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 	while (IsIntervalFull(m_tLast, m_nAnimationInterval)) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>¼<EFBFBD>¼ʱ<C2BC><CAB1>
 | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 		m_tLast.QuadPart += m_nAnimationInterval.QuadPart; | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 		// <20><><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>֡
 | 
					
						
							|  |  |  |  | 		reinterpret_cast<ESprite*>(m_pTarget)->loadFrom(m_vFrames[m_nFrameIndex]); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		m_nFrameIndex++; | 
					
						
							|  |  |  |  | 		// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		if (m_nFrameIndex == m_vFrames.size()) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			this->stop(); | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-19 12:47:36 +08:00
										 |  |  |  | void e2d::EAnimation::_reset() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	EAction::_reset(); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	m_nFrameIndex = 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::EAnimation::addFrame(ESpriteFrame * frame) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (frame) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_vFrames.push_back(frame); | 
					
						
							|  |  |  |  | 		frame->retain(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::EAnimation * e2d::EAnimation::clone() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 	auto a = new EAnimation(ToMilliseconds(m_nAnimationInterval.QuadPart)); | 
					
						
							|  |  |  |  | 	for (auto frame = m_vFrames.begin(); frame != m_vFrames.end(); frame++) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 21:51:07 +08:00
										 |  |  |  | 		a->addFrame((*frame)); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::EAnimation * e2d::EAnimation::reverse() const | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	auto a = this->clone(); | 
					
						
							|  |  |  |  | 	a->m_vFrames.reserve(m_vFrames.size()); | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } |