fix backward animation playing

This commit is contained in:
David Rose 2001-12-21 19:34:15 +00:00
parent cc32ef9d8c
commit dce135ab10
2 changed files with 16 additions and 3 deletions

View File

@ -72,7 +72,10 @@ get_frame_rate() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int AnimControl:: INLINE int AnimControl::
get_frame() const { get_frame() const {
return (int)(_frame + 0.0001); // We have to use floor() here instead of simply casting the number
// to an integer, becase the frame number might have become
// negative.
return (int)floor(_frame + 0.0001);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -382,7 +382,12 @@ advance_time(double time) {
do_actions_backward(orig_frame-1, new_frame); do_actions_backward(orig_frame-1, new_frame);
} else { } else {
if (do_actions_backward(orig_frame-1, 0)) { if (do_actions_backward(orig_frame-1, 0)) {
_frame = _frame - (int)(_frame / num_frames) * num_frames; // floor() is correct here, instead of simply an integer
// cast, because we are using floating-point arithmetic
// anyway (no need to convert to integer format and back
// again), and because we need correct behavior when the
// frame number is negative.
_frame = _frame - floor(_frame / num_frames) * num_frames;
new_frame = get_frame(); new_frame = get_frame();
do_actions_backward(get_num_frames(), new_frame); do_actions_backward(get_num_frames(), new_frame);
} }
@ -394,7 +399,12 @@ advance_time(double time) {
do_actions_forward(orig_frame+1, new_frame); do_actions_forward(orig_frame+1, new_frame);
} else { } else {
if (do_actions_forward(orig_frame+1, get_num_frames()-1)) { if (do_actions_forward(orig_frame+1, get_num_frames()-1)) {
_frame = _frame - (int)(_frame / num_frames) * num_frames; // floor() is correct here, instead of simply an integer
// cast, because we are using floating-point arithmetic
// anyway (no need to convert to integer format and back
// again), and because we need correct behavior when the
// frame number is negative.
_frame = _frame - floor(_frame / num_frames) * num_frames;
new_frame = get_frame(); new_frame = get_frame();
do_actions_forward(0, new_frame); do_actions_forward(0, new_frame);
} }