I have an array of sprites that are displayed in-order to make an animation. There is code in an update loop that has access to a value 'time' indicating how far along the animation is. Time is a float between 0 and 1 inclusive. It uses this value to calculate which frame to display.
update(time) {
frames // An array of animation frames
current_frame_index = time / animation_length
display_frame(frame[current_frame_index])
}
This works if you assume that each frame is displayed for the same amount of time.
I would like to enhance this by allowing frames to have arbitrarily defined durations. So if I have a set of frames and durations:
name duration
frame_one 0.2
frame_two 1.1
frame_three 1.0
frame_four 0.75
frame_five 1.4
and a value indicating the animation's progress, how can I determine which frame to display?
Thanks!