| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2daction.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Animation::Animation()  | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(1) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 18:46:18 +08:00
										 |  |  |  | e2d::Animation::Animation(double interval) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(interval) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 20:22:41 +08:00
										 |  |  |  | #ifdef HIGHER_THAN_VS2012
 | 
					
						
							| 
									
										
										
										
											2018-04-01 13:16:07 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | e2d::Animation::Animation(const std::initializer_list<Image*>& vImages) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(1) | 
					
						
							| 
									
										
										
										
											2018-04-01 00:04:33 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	this->add(vImages); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | e2d::Animation::Animation(double interval, const std::initializer_list<Image*>& vImages) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(interval) | 
					
						
							| 
									
										
										
										
											2018-03-27 18:46:18 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 	this->add(vImages); | 
					
						
							| 
									
										
										
										
											2018-03-27 18:46:18 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 13:16:07 +08:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Animation::Animation(int number, Image * frame, ...) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(1) | 
					
						
							| 
									
										
										
										
											2018-04-01 13:16:07 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	Image ** ppImage = &frame; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	while (number > 0) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); | 
					
						
							|  |  |  |  | 		this->add(*ppImage); | 
					
						
							|  |  |  |  | 		ppImage++; | 
					
						
							|  |  |  |  | 		number--; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Animation::Animation(double interval, int number, Image * frame, ...) | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _nFrameIndex(0) | 
					
						
							|  |  |  |  | 	, _fInterval(interval) | 
					
						
							| 
									
										
										
										
											2018-04-01 13:16:07 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	Image ** ppImage = &frame; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	while (number > 0) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); | 
					
						
							|  |  |  |  | 		this->add(*ppImage); | 
					
						
							|  |  |  |  | 		ppImage++; | 
					
						
							|  |  |  |  | 		number--; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Animation::~Animation() | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | void e2d::Animation::setInterval(double interval) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_fInterval = max(interval, 0); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Animation::_init() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-30 16:49:44 +08:00
										 |  |  |  | 	ActionBase::_init(); | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Animation::_update() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-30 16:49:44 +08:00
										 |  |  |  | 	ActionBase::_update(); | 
					
						
							| 
									
										
										
										
											2017-11-03 12:51:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_pTarget == nullptr) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		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>㹻
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	while ((Time::getTotalTime() - _fLast) >= _fInterval) | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>¼<EFBFBD>¼ʱ<C2BC><CAB1>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		_fLast += _fInterval; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 		// <20><><EFBFBD>عؼ<D8B9>֡
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		static_cast<Sprite*>(_pTarget)->open(_vFrames[_nFrameIndex]); | 
					
						
							|  |  |  |  | 		_nFrameIndex++; | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		if (_nFrameIndex == _vFrames.size()) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			this->stop(); | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Animation::reset() | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-30 16:49:44 +08:00
										 |  |  |  | 	ActionBase::reset(); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_nFrameIndex = 0; | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | void e2d::Animation::destroy() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-30 16:49:44 +08:00
										 |  |  |  | 	ActionBase::destroy(); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	for (auto frame : _vFrames) | 
					
						
							| 
									
										
										
										
											2018-04-21 18:22:01 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SafeRelease(&frame); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | void e2d::Animation::add(Image * frame) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (frame) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		_vFrames.push_back(frame); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		frame->retain(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 20:22:41 +08:00
										 |  |  |  | #ifdef HIGHER_THAN_VS2012
 | 
					
						
							| 
									
										
										
										
											2018-05-08 11:37:11 +08:00
										 |  |  |  | void e2d::Animation::add(const std::initializer_list<Image*>& vImages) | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	for (const auto &image : vImages) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->add(image); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-01 13:16:07 +08:00
										 |  |  |  | #else
 | 
					
						
							|  |  |  |  | void e2d::Animation::add(int number, Image * frame, ...) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	Image ** ppImage = &frame; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	while (number > 0) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!"); | 
					
						
							|  |  |  |  | 		this->add(*ppImage); | 
					
						
							|  |  |  |  | 		ppImage++; | 
					
						
							|  |  |  |  | 		number--; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Animation * e2d::Animation::clone() const | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	auto a = new Animation(_fInterval); | 
					
						
							|  |  |  |  | 	for (auto frame : _vFrames) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-03-31 18:12:01 +08:00
										 |  |  |  | 		a->add(frame); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return a; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Animation * e2d::Animation::reverse() const | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	auto a = this->clone(); | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	a->_vFrames.reserve(_vFrames.size()); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	return a; | 
					
						
							| 
									
										
										
										
											2017-10-19 00:50:04 +08:00
										 |  |  |  | } |