void UPaperFlipbookComponent::TickFlipbook(float DeltaTime) { bool bIsFinished = false; if (bPlaying) { const float TimelineLength = GetFlipbookLength(); const float EffectiveDeltaTime = DeltaTime * (bReversePlayback ? (-PlayRate) : (PlayRate)); float NewPosition = AccumulatedTime + EffectiveDeltaTime; if (EffectiveDeltaTime > 0.0f) { if (NewPosition > TimelineLength) { if (bLooping) { // If looping, play to end, jump to start, and set target to somewhere near the beginning. SetPlaybackPosition(TimelineLength, true); SetPlaybackPosition(0.0f, false); if (TimelineLength > 0.0f) { while (NewPosition > TimelineLength) { NewPosition -= TimelineLength; } } else { NewPosition = 0.0f; } } else { // If not looping, snap to end and stop playing. NewPosition = TimelineLength; Stop(); bIsFinished = true; } } } else { if (NewPosition < 0.0f) { if (bLooping) { // If looping, play to start, jump to end, and set target to somewhere near the end. SetPlaybackPosition(0.0f, true); SetPlaybackPosition(TimelineLength, false); if (TimelineLength > 0.0f) { while (NewPosition < 0.0f) { NewPosition += TimelineLength; } } else { NewPosition = 0.0f; } } else { // If not looping, snap to start and stop playing. NewPosition = 0.0f; Stop(); bIsFinished = true; } } } SetPlaybackPosition(NewPosition, true); } // Notify user that the flipbook finished playing if (bIsFinished) { OnFinishedPlaying.Broadcast(); } }
void FTimeline::ReverseFromEnd() { SetPlaybackPosition(GetTimelineLength(), false); Reverse(); }
void FTimeline::TickTimeline(float DeltaTime) { bool bIsFinished = false; if(bPlaying) { float NewPosition = Position; const float TimelineLength = GetTimelineLength(); if(!bReversePlayback) { NewPosition = Position + (DeltaTime * PlayRate); if(NewPosition > TimelineLength) { // If looping, play to end, jump to start, and set target to somewhere near the beginning. if(bLooping) { SetPlaybackPosition(TimelineLength, true); SetPlaybackPosition(0.f, false); if( TimelineLength > 0.f ) { while(NewPosition > TimelineLength) { NewPosition -= TimelineLength; } } else { NewPosition = 0.f; } } // If not looping, snap to end and stop playing. else { NewPosition = TimelineLength; Stop(); bIsFinished = true; } } } else { NewPosition = Position - (DeltaTime * PlayRate); if(NewPosition < 0.f) { // If looping, play to start, jump to end, and set target to somewhere near the end. if(bLooping) { SetPlaybackPosition(0.f, true); SetPlaybackPosition(TimelineLength, false); if( TimelineLength > 0.f ) { while(NewPosition < 0.f) { NewPosition += TimelineLength; } } else { NewPosition = 0.f; } } // If not looping, snap to start and stop playing. else { NewPosition = 0.f; Stop(); bIsFinished = true; } } } SetPlaybackPosition(NewPosition, true); } // Notify user that timeline finished if (bIsFinished) { TimelineFinishedFunc.ExecuteIfBound(); TimelineFinishFuncStatic.ExecuteIfBound(); } }
void FTimeline::SetNewTime(float NewTime) { // Ensure value is sensible NewTime = FMath::Clamp<float>(NewTime, 0.0f, Length); SetPlaybackPosition(NewTime, false); }
void FTimeline::PlayFromStart() { SetPlaybackPosition(0.f, false); Play(); }