| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | #include "..\easy2d.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ActionFrames::ActionFrames() : | 
					
						
							|  |  |  |  | 	m_nFrameIndex(0) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// ֡<><D6A1><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC> .5s ˢ<><CBA2>һ<EFBFBD><D2BB>
 | 
					
						
							|  |  |  |  | 	setInterval(500); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 16:18:45 +08:00
										 |  |  |  | ActionFrames::ActionFrames(UINT frameDelay) : | 
					
						
							|  |  |  |  | 	m_nFrameIndex(0) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	setInterval(frameDelay); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | ActionFrames::~ActionFrames() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	for (auto frame : m_vFrames) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		frame->release(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void ActionFrames::_init() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-08 13:26:42 +08:00
										 |  |  |  | 	Action::_init(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 	// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
 | 
					
						
							|  |  |  |  | 	QueryPerformanceCounter(&m_nLast); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-08 12:30:45 +08:00
										 |  |  |  | void ActionFrames::_exec(LARGE_INTEGER nNow) | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20>ж<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>㹻
 | 
					
						
							|  |  |  |  | 	while (nNow.QuadPart - m_nLast.QuadPart > m_nAnimationInterval.QuadPart) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>¼ʱ<C2BC><CAB1>
 | 
					
						
							|  |  |  |  | 		m_nLast.QuadPart = nNow.QuadPart - (nNow.QuadPart % m_nAnimationInterval.QuadPart); | 
					
						
							| 
									
										
										
										
											2017-10-06 02:32:33 +08:00
										 |  |  |  | 		m_pTargetSprite->setImage(m_vFrames[m_nFrameIndex]); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		m_nFrameIndex++; | 
					
						
							| 
									
										
										
										
											2017-09-30 16:18:45 +08:00
										 |  |  |  | 		// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		if (m_nFrameIndex == m_vFrames.size()) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-08 12:30:45 +08:00
										 |  |  |  | 			this->stop(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void ActionFrames::_reset() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-08 12:30:45 +08:00
										 |  |  |  | 	Action::_reset(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 	m_nFrameIndex = 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void ActionFrames::addFrame(Image * frame) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (frame) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_vFrames.push_back(frame); | 
					
						
							|  |  |  |  | 		frame->retain(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 16:18:45 +08:00
										 |  |  |  | ActionFrames * ActionFrames::copy() const | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-09-30 16:18:45 +08:00
										 |  |  |  | 	auto a = new ActionFrames(this->m_nMilliSeconds); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 	for (auto f : m_vFrames) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		a->addFrame(f); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | ActionFrames * ActionFrames::reverse() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-09-30 16:18:45 +08:00
										 |  |  |  | 	auto a = this->copy(); | 
					
						
							| 
									
										
										
										
											2017-09-27 17:56:28 +08:00
										 |  |  |  | 	a->m_vFrames.reserve(m_vFrames.size()); | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } |