[deploy] update CustomAnimation
This commit is contained in:
parent
6a653cce8a
commit
266453a907
|
|
@ -263,9 +263,9 @@ inline AnimationWrapper RotateTo(kiwano::Duration duration, float rotation)
|
|||
/// @brief 创建自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
inline AnimationWrapper Custom(kiwano::Duration duration, TweenFunc tween_func)
|
||||
inline AnimationWrapper Custom(kiwano::Duration duration, Function<void(Actor*, float)> tween_func)
|
||||
{
|
||||
return AnimationWrapper(new CustomAnimation(duration, tween_func));
|
||||
return AnimationWrapper(CustomAnimation::Create(duration, tween_func));
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
|
|
|
|||
|
|
@ -23,29 +23,51 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
CustomAnimation::CustomAnimation(Duration duration, TweenFunc tween_func)
|
||||
CustomAnimation::CustomAnimation(Duration duration)
|
||||
: TweenAnimation(duration)
|
||||
, tween_func_(tween_func)
|
||||
{
|
||||
}
|
||||
|
||||
CustomAnimation* CustomAnimation::Clone() const
|
||||
CustomAnimationPtr CustomAnimation::Create(Duration duration, Function<void(Actor*, float)> tween_func)
|
||||
{
|
||||
CustomAnimation* ptr = new CustomAnimation(GetDuration(), tween_func_);
|
||||
DoClone(ptr);
|
||||
class CallbackCustomAnimation : public CustomAnimation
|
||||
{
|
||||
public:
|
||||
CallbackCustomAnimation(Duration duration, Function<void(Actor*, float)> tween_func)
|
||||
: CustomAnimation(duration)
|
||||
, tween_func_(tween_func)
|
||||
{
|
||||
}
|
||||
|
||||
void Init(Actor* target) override
|
||||
{
|
||||
if (!tween_func_)
|
||||
this->Done();
|
||||
}
|
||||
|
||||
void OnAnimationUpdate(Actor* target, float frac) override
|
||||
{
|
||||
if (tween_func_)
|
||||
tween_func_(target, frac);
|
||||
}
|
||||
|
||||
CallbackCustomAnimation* Clone() const
|
||||
{
|
||||
CallbackCustomAnimation* ptr = new CallbackCustomAnimation(GetDuration(), tween_func_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
Function<void(Actor*, float)> tween_func_;
|
||||
};
|
||||
CustomAnimationPtr ptr = new CallbackCustomAnimation(duration, tween_func);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void CustomAnimation::Init(Actor* target)
|
||||
{
|
||||
if (!tween_func_)
|
||||
this->Done();
|
||||
}
|
||||
|
||||
void CustomAnimation::UpdateTween(Actor* target, float frac)
|
||||
{
|
||||
if (tween_func_)
|
||||
tween_func_(target, frac);
|
||||
OnAnimationUpdate(target, frac);
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -30,34 +30,35 @@ KGE_DECLARE_SMART_PTR(CustomAnimation);
|
|||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画回调函数
|
||||
/// @details 在动画更新时回调该函数,第一个参数是执行动画的目标,第二个参数是动画进度(0.0 - 1.0)
|
||||
using TweenFunc = Function<void(Actor* /* target */, float /* frac */)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 自定义动画
|
||||
class KGE_API CustomAnimation : public TweenAnimation
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建自定义动画
|
||||
/// @param duration 动画时长
|
||||
CustomAnimation(Duration duration);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
CustomAnimation(Duration duration, TweenFunc tween_func);
|
||||
static CustomAnimationPtr Create(Duration duration, Function<void(Actor*, float)> tween_func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画回调函数
|
||||
TweenFunc GetTweenFunc() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画回调函数
|
||||
void SetTweenFunc(const TweenFunc& tween_func);
|
||||
/// @brief 动画更新时
|
||||
/// @param target 执行动画的目标
|
||||
/// @param frac 动画进度(0.0 - 1.0)
|
||||
virtual void OnAnimationUpdate(Actor* target, float frac) = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
CustomAnimation* Clone() const override;
|
||||
CustomAnimation* Clone() const override
|
||||
{
|
||||
KGE_ERRORF("Clone() not supported in CustomAnimation");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
|
|
@ -68,26 +69,9 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
||||
void UpdateTween(Actor* target, float frac) override;
|
||||
|
||||
private:
|
||||
TweenFunc tween_func_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
inline TweenFunc CustomAnimation::GetTweenFunc() const
|
||||
{
|
||||
return tween_func_;
|
||||
}
|
||||
|
||||
inline void CustomAnimation::SetTweenFunc(const TweenFunc& tween_func)
|
||||
{
|
||||
tween_func_ = tween_func;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
Loading…
Reference in New Issue