From add0f0d960ae9c5e539f401efdaa9da4f157555e Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sat, 14 Aug 2004 11:50:24 +0000 Subject: [PATCH] Improvements. SVN-Revision: 1775 --- lib/special/sprite.cpp | 14 +++++++------- lib/special/sprite.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/special/sprite.cpp b/lib/special/sprite.cpp index d9134885e..f676c085a 100644 --- a/lib/special/sprite.cpp +++ b/lib/special/sprite.cpp @@ -150,20 +150,20 @@ else last_tick = SDL_GetTicks(); -if(!animation_reversed) +if(animation_reversed) { - if((unsigned int)frame >= action->surfaces.size()) + if((unsigned int)frame < 0) { - frame = 0; + frame = get_frames()-1; if(animation_loops > 0) animation_loops--; } } else { - if((unsigned int)frame < 0) + if((unsigned int)frame >= action->surfaces.size()) { - frame = get_frames()-1; + frame = 0; if(animation_loops > 0) animation_loops--; } @@ -176,8 +176,8 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer, { update(); - if((int)frame >= get_frames()) - std::cerr << "Warning: frame higher than total frames!\n"; + if((int)frame >= get_frames() || (int)frame < 0) + std::cerr << "Warning: frame higher than total frames or lower than 0!\n"; else context.draw_surface(action->surfaces[(int)frame], pos - Vector(action->x_hotspot, action->y_hotspot), layer, drawing_effect); diff --git a/lib/special/sprite.h b/lib/special/sprite.h index f84894582..fdf83a5af 100644 --- a/lib/special/sprite.h +++ b/lib/special/sprite.h @@ -90,7 +90,7 @@ namespace SuperTux { return (int)frame; } /** Set current frame */ void set_frame(int frame_) - { frame = frame_; } + { if(frame_ > get_frames()) frame = 0; else frame = frame_; } Surface* get_frame(unsigned int frame) { if(frame < action->surfaces.size()) -- 2.11.0