[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 创建自定义动画
|
/// @brief 创建自定义动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param tween_func 动画回调函数
|
/// @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
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -23,29 +23,51 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
CustomAnimation::CustomAnimation(Duration duration, TweenFunc tween_func)
|
CustomAnimation::CustomAnimation(Duration duration)
|
||||||
: TweenAnimation(duration)
|
: TweenAnimation(duration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomAnimationPtr CustomAnimation::Create(Duration duration, Function<void(Actor*, float)> tween_func)
|
||||||
|
{
|
||||||
|
class CallbackCustomAnimation : public CustomAnimation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CallbackCustomAnimation(Duration duration, Function<void(Actor*, float)> tween_func)
|
||||||
|
: CustomAnimation(duration)
|
||||||
, tween_func_(tween_func)
|
, tween_func_(tween_func)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAnimation* CustomAnimation::Clone() const
|
void Init(Actor* target) override
|
||||||
{
|
{
|
||||||
CustomAnimation* ptr = new CustomAnimation(GetDuration(), tween_func_);
|
|
||||||
DoClone(ptr);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CustomAnimation::Init(Actor* target)
|
|
||||||
{
|
|
||||||
if (!tween_func_)
|
if (!tween_func_)
|
||||||
this->Done();
|
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::UpdateTween(Actor* target, float frac)
|
void CustomAnimation::UpdateTween(Actor* target, float frac)
|
||||||
{
|
{
|
||||||
if (tween_func_)
|
OnAnimationUpdate(target, frac);
|
||||||
tween_func_(target, frac);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // 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
|
/// \~chinese
|
||||||
/// @brief 自定义动画
|
/// @brief 自定义动画
|
||||||
class KGE_API CustomAnimation : public TweenAnimation
|
class KGE_API CustomAnimation : public TweenAnimation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 创建自定义动画
|
||||||
|
/// @param duration 动画时长
|
||||||
|
CustomAnimation(Duration duration);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建自定义动画
|
/// @brief 创建自定义动画
|
||||||
/// @param duration 动画时长
|
/// @param duration 动画时长
|
||||||
/// @param tween_func 动画回调函数
|
/// @param tween_func 动画回调函数
|
||||||
CustomAnimation(Duration duration, TweenFunc tween_func);
|
static CustomAnimationPtr Create(Duration duration, Function<void(Actor*, float)> tween_func);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取动画回调函数
|
/// @brief 动画更新时
|
||||||
TweenFunc GetTweenFunc() const;
|
/// @param target 执行动画的目标
|
||||||
|
/// @param frac 动画进度(0.0 - 1.0)
|
||||||
/// \~chinese
|
virtual void OnAnimationUpdate(Actor* target, float frac) = 0;
|
||||||
/// @brief 设置动画回调函数
|
|
||||||
void SetTweenFunc(const TweenFunc& tween_func);
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的拷贝对象
|
/// @brief 获取该动画的拷贝对象
|
||||||
CustomAnimation* Clone() const override;
|
CustomAnimation* Clone() const override
|
||||||
|
{
|
||||||
|
KGE_ERRORF("Clone() not supported in CustomAnimation");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取该动画的倒转
|
/// @brief 获取该动画的倒转
|
||||||
|
|
@ -68,26 +69,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init(Actor* target) override;
|
|
||||||
|
|
||||||
void UpdateTween(Actor* target, float frac) 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
|
} // namespace kiwano
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue