From 3a93143e5296e1978b283e86205a61745c48fb0f Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Fri, 22 Aug 2014 14:25:41 +0800 Subject: [PATCH] Fix tween seek, add tell function --- scene/animation/tween.cpp | 32 ++++++++++++++++++++++++++------ scene/animation/tween.h | 3 ++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 799b1d19c97..abb287bc66d 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -131,7 +131,8 @@ void Tween::_bind_methods() { ObjectTypeDB::bind_method(_MD("resume_all"),&Tween::resume_all ); ObjectTypeDB::bind_method(_MD("remove","node","key"),&Tween::remove ); ObjectTypeDB::bind_method(_MD("remove_all"),&Tween::remove_all ); - ObjectTypeDB::bind_method(_MD("seek"),&Tween::seek ); + ObjectTypeDB::bind_method(_MD("seek","time"),&Tween::seek ); + ObjectTypeDB::bind_method(_MD("tell"),&Tween::tell ); ObjectTypeDB::bind_method(_MD("get_runtime"),&Tween::get_runtime ); ObjectTypeDB::bind_method(_MD("interpolate_property","node","property","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_property, DEFVAL(0) ); @@ -615,10 +616,17 @@ bool Tween::seek(real_t p_time) { InterpolateData& data = E->get(); data.elapsed = p_time; - if(data.elapsed < data.delay) + if(data.elapsed < data.delay) { + + data.finish = false; continue; - else if(data.elapsed > (data.delay + data.times_in_sec)) + } + else if(data.elapsed >= (data.delay + data.times_in_sec)) { + + data.finish = true; data.elapsed = (data.delay + data.times_in_sec); + } else + data.finish = false; switch(data.type) { @@ -636,12 +644,24 @@ bool Tween::seek(real_t p_time) { return true; } -real_t Tween::get_runtime() { +real_t Tween::tell() const { + + real_t pos = 0; + for(const List::Element *E=interpolates.front();E;E=E->next()) { + + const InterpolateData& data = E->get(); + if(data.elapsed > pos) + pos = data.elapsed; + } + return pos; +} + +real_t Tween::get_runtime() const { real_t runtime = 0; - for(List::Element *E=interpolates.front();E;E=E->next()) { + for(const List::Element *E=interpolates.front();E;E=E->next()) { - InterpolateData& data = E->get(); + const InterpolateData& data = E->get(); real_t t = data.delay + data.times_in_sec; if(t > runtime) runtime = t; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 8718528ad69..5d1d9ba5fce 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -147,7 +147,8 @@ public: bool remove_all(); bool seek(real_t p_time); - real_t get_runtime(); + real_t tell() const; + real_t get_runtime() const; bool interpolate_property(Node *p_node , String p_property