| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | // 
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | #include "ActionTween.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | #include "Geometry.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | #include "include-forwards.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | #include "Node.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | #include <cfloat>
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace easy2d | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	// ActionTween
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ActionTween::ActionTween() | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: elapsed_() | 
					
						
							|  |  |  | 		, duration_() | 
					
						
							|  |  |  | 		, ease_func_(math::Linear) | 
					
						
							|  |  |  | 		, ease_type_(EaseFunc::Linear) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ActionTween::ActionTween(Duration duration, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: elapsed_() | 
					
						
							|  |  |  | 		, ease_func_(math::Linear) | 
					
						
							|  |  |  | 		, ease_type_(EaseFunc::Linear) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SetDuration(duration); | 
					
						
							|  |  |  | 		SetEaseFunction(func); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::SetEaseFunction(EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ease_type_ = func; | 
					
						
							|  |  |  | 		switch (func) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		case EaseFunc::Linear: | 
					
						
							|  |  |  | 			ease_func_ = math::Linear; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | 		case EaseFunc::EaseIn: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseIn(2.f); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | 		case EaseFunc::EaseOut: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseOut(2.f); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | 		case EaseFunc::EaseInOut: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseInOut(2.f); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ExpoIn: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseExponentialIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ExpoOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseExponentialOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ExpoInOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseExponentialInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::BounceIn: | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			ease_func_ = math::EaseBounceIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::BounceOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			ease_func_ = math::EaseBounceOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::BounceInOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			ease_func_ = math::EaseBounceInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ElasticIn: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseElasticIn(0.3f); | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ElasticOut: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseElasticOut(0.3f); | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::ElasticInOut: | 
					
						
							| 
									
										
										
										
											2018-11-21 00:01:37 +08:00
										 |  |  | 			ease_func_ = MakeEaseElasticInOut(0.3f); | 
					
						
							| 
									
										
										
										
											2018-11-20 23:47:56 +08:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::SineIn: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseSineIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::SineOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseSineOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::SineInOut: | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			ease_func_ = math::EaseSineInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-21 01:04:34 +08:00
										 |  |  | 		case EaseFunc::BackIn: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseBackIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::BackOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseBackOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::BackInOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseBackInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuadIn: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuadIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuadOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuadOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuadInOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuadInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::CubicIn: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseCubicIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::CubicOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseCubicOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::CubicInOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseCubicInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuartIn: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuartIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuartOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuartOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuartInOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuartInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuintIn: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuintIn; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuintOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuintOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case EaseFunc::QuintInOut: | 
					
						
							|  |  |  | 			ease_func_ = math::EaseQuintInOut; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::SetEaseFunction(EaseFunction func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ease_func_ = func; | 
					
						
							|  |  |  | 		ease_type_ = EaseFunc(-1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::Reset() | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Action::Reset(); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		elapsed_ = Duration{}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	Duration ActionTween::GetDuration() const | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return duration_; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		Action::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::Update(Node* target, Duration dt) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 		Action::Update(target, dt); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		float step; | 
					
						
							| 
									
										
										
										
											2018-11-14 16:39:24 +08:00
										 |  |  | 		if (duration_.IsZero()) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			step = 1.f; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 			elapsed_ += dt; | 
					
						
							|  |  |  | 			step = std::min(elapsed_ / duration_, 1.f); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		if ((1.f - step) <= FLT_EPSILON) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			this->Stop(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		UpdateStep(target, ease_func_(step)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	void ActionTween::SetDuration(Duration duration) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		duration_ = duration; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Move Action
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	MoveBy::MoveBy(Duration duration, Point const& vector, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		delta_pos_ = vector; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void MoveBy::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		if (target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			prev_pos_ = start_pos_ = target->GetPosition(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void MoveBy::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		Point diff = target->GetPosition() - prev_pos_; | 
					
						
							|  |  |  | 		start_pos_ = start_pos_ + diff; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		Point new_pos = start_pos_ + (delta_pos_ * step); | 
					
						
							|  |  |  | 		target->SetPosition(new_pos); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		prev_pos_ = new_pos; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr MoveBy::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) MoveBy(duration_, delta_pos_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr MoveBy::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) MoveBy(duration_, -delta_pos_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	MoveTo::MoveTo(Duration duration, Point const& pos, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: MoveBy(duration, Point(), func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		end_pos_ = pos; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr MoveTo::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) MoveTo(duration_, end_pos_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void MoveTo::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		MoveBy::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		delta_pos_ = end_pos_ - start_pos_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Jump Action
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	JumpBy::JumpBy(Duration duration, Point const& vec, float height, int jumps, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		, delta_pos_(vec) | 
					
						
							|  |  |  | 		, height_(height) | 
					
						
							|  |  |  | 		, jumps_(jumps) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr JumpBy::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr JumpBy::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) JumpBy(duration_, -delta_pos_, height_, jumps_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void JumpBy::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		if (target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			prev_pos_ = start_pos_ = target->GetPosition(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void JumpBy::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		float frac = fmod(step * jumps_, 1.f); | 
					
						
							|  |  |  | 		float x = delta_pos_.x * step; | 
					
						
							|  |  |  | 		float y = height_ * 4 * frac * (1 - frac); | 
					
						
							|  |  |  | 		y += delta_pos_.y * step; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		Point diff = target->GetPosition() - prev_pos_; | 
					
						
							|  |  |  | 		start_pos_ = diff + start_pos_; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		Point new_pos = start_pos_ + Point(x, y); | 
					
						
							|  |  |  | 		target->SetPosition(new_pos); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		prev_pos_ = new_pos; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	JumpTo::JumpTo(Duration duration, Point const& pos, float height, int jumps, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: JumpBy(duration, Point(), height, jumps, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		, end_pos_(pos) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr JumpTo::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) JumpTo(duration_, end_pos_, height_, jumps_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void JumpTo::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		JumpBy::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		delta_pos_ = end_pos_ - start_pos_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Scale Action
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ScaleBy::ScaleBy(Duration duration, float scale, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		delta_x_ = scale; | 
					
						
							|  |  |  | 		delta_y_ = scale; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ScaleBy::ScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		delta_x_ = scale_x; | 
					
						
							|  |  |  | 		delta_y_ = scale_y; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void ScaleBy::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		if (target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			start_scale_x_ = target->GetScaleX(); | 
					
						
							|  |  |  | 			start_scale_y_ = target->GetScaleY(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void ScaleBy::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		target->SetScale(start_scale_x_ + delta_x_ * step, start_scale_y_ + delta_y_ * step); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr ScaleBy::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr ScaleBy::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ScaleTo::ScaleTo(Duration duration, float scale, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: ScaleBy(duration, 0, 0, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		end_scale_x_ = scale; | 
					
						
							|  |  |  | 		end_scale_y_ = scale; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	ScaleTo::ScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: ScaleBy(duration, 0, 0, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		end_scale_x_ = scale_x; | 
					
						
							|  |  |  | 		end_scale_y_ = scale_y; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr ScaleTo::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) ScaleTo(duration_, end_scale_x_, end_scale_y_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void ScaleTo::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		ScaleBy::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		delta_x_ = end_scale_x_ - start_scale_x_; | 
					
						
							|  |  |  | 		delta_y_ = end_scale_y_ - start_scale_y_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Opacity Action
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	OpacityBy::OpacityBy(Duration duration, float opacity, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		delta_val_ = opacity; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void OpacityBy::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		if (target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			start_val_ = target->GetOpacity(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void OpacityBy::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		target->SetOpacity(start_val_ + delta_val_ * step); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr OpacityBy::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) OpacityBy(duration_, delta_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr OpacityBy::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) OpacityBy(duration_, -delta_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	OpacityTo::OpacityTo(Duration duration, float opacity, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: OpacityBy(duration, 0, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		end_val_ = opacity; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr OpacityTo::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) OpacityTo(duration_, end_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void OpacityTo::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		OpacityBy::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		delta_val_ = end_val_ - start_val_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	FadeIn::FadeIn(Duration duration, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: OpacityTo(duration, 1, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	FadeOut::FadeOut(Duration duration, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: OpacityTo(duration, 0, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// Rotate Action
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	RotateBy::RotateBy(Duration duration, float rotation, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-15 01:02:05 +08:00
										 |  |  | 		, delta_val_(rotation) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void RotateBy::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		if (target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 			start_val_ = target->GetRotation(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void RotateBy::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		target->SetRotation(start_val_ + delta_val_ * step); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr RotateBy::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) RotateBy(duration_, delta_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr RotateBy::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) RotateBy(duration_, -delta_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	RotateTo::RotateTo(Duration duration, float rotation, EaseFunc func) | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		: RotateBy(duration, 0, func) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		end_val_ = rotation; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr RotateTo::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new (std::nothrow) RotateTo(duration_, end_val_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 	void RotateTo::Init(Node* target) | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-14 01:34:41 +08:00
										 |  |  | 		RotateBy::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | 		delta_val_ = end_val_ - start_val_; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 	// PathAction
 | 
					
						
							|  |  |  | 	//-------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 	PathAction::PathAction(Duration duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func) | 
					
						
							|  |  |  | 		: ActionTween(duration, func) | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 		, start_(start) | 
					
						
							|  |  |  | 		, end_(end) | 
					
						
							|  |  |  | 		, geo_(geo) | 
					
						
							|  |  |  | 		, rotating_(rotating) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr PathAction::Clone() const | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new PathAction(duration_, geo_, rotating_, start_, end_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 21:58:01 +08:00
										 |  |  | 	ActionPtr PathAction::Reverse() const | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 		return new PathAction(duration_, geo_, rotating_, end_, start_, ease_type_); | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | 	void PathAction::Init(Node * target) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 15:14:55 +08:00
										 |  |  | 		ActionTween::Init(target); | 
					
						
							| 
									
										
										
										
											2018-11-23 14:55:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (target) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			start_pos_ = target->GetPosition(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 	void PathAction::UpdateStep(Node* target, float step) | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 		float length = geo_->GetLength() * std::min(std::max((end_ - start_) * step + start_, 0.f), 1.f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point point, tangent; | 
					
						
							|  |  |  | 		if (geo_->ComputePointAt(length, &point, &tangent)) | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 			target->SetPosition(start_pos_ + point); | 
					
						
							| 
									
										
										
										
											2018-11-20 19:55:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 			if (rotating_) | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-01-26 17:18:31 +08:00
										 |  |  | 				float ac = math::Acos(tangent.x); | 
					
						
							|  |  |  | 				float rotation = (tangent.y < 0.f) ? 360.f - ac : ac; | 
					
						
							|  |  |  | 				target->SetRotation(rotation); | 
					
						
							| 
									
										
										
										
											2018-11-20 13:48:49 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  | } |