X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsprite%2Fsprite.cpp;h=1c8d0bf80b17c9087c8229b245bdd488d0e3c6e8;hb=0f0e6a3689e5d810ec55b68ff455210b1081a021;hp=78972c923aee30dee6db518b5fbd0c50bcfaed6f;hpb=b08db3ab7e6d4447f8005dcf5a6c9e61a7f8e937;p=supertux.git diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 78972c923..1c8d0bf80 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -25,6 +25,7 @@ #include "sprite.hpp" #include "video/drawing_context.hpp" +#include "msg.hpp" Sprite::Sprite(SpriteData& newdata) : data(newdata), frame(0), animation_loops(-1) @@ -55,9 +56,7 @@ Sprite::set_action(const std::string& name, int loops) SpriteData::Action* newaction = data.get_action(name); if(!newaction) { -#ifdef DEBUG - std::cerr << "Action '" << name << "' not found.\n"; -#endif + msg_debug("Action '" << name << "' not found."); return; } @@ -67,7 +66,7 @@ Sprite::set_action(const std::string& name, int loops) } bool -Sprite::check_animation() +Sprite::animation_done() { return animation_loops == 0; } @@ -75,7 +74,7 @@ Sprite::check_animation() void Sprite::update() { - if(animation_loops == 0) + if(animation_done()) return; Uint32 ticks = SDL_GetTicks(); @@ -85,11 +84,11 @@ Sprite::update() frame += frame_inc; if(frame >= get_frames()) { - frame = fmodf(frame+get_frames(), get_frames()); - + frame = fmodf(frame, get_frames()); + animation_loops--; - if(animation_loops == 0) - frame = 0; + if(animation_done()) + frame = get_frames()-1; } } @@ -100,9 +99,9 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer) update(); if((int)frame >= get_frames() || (int)frame < 0) - std::cerr << "Warning: frame out of range: " << (int)frame + msg_warning("frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() - << "/" << get_action_name() << std::endl; + << "/" << get_action_name()); else context.draw_surface(action->surfaces[(int)frame], pos - Vector(action->x_offset, action->y_offset), @@ -117,9 +116,9 @@ Sprite::draw_part(DrawingContext& context, const Vector& source, update(); if((int)frame >= get_frames() || (int)frame < 0) - std::cerr << "Warning: frame out of range: " << (int)frame + msg_warning("frame out of range: " << (int)frame << "/" << get_frames() << " at sprite: " << get_name() - << "/" << get_action_name() << std::endl; + << "/" << get_action_name()); else context.draw_surface_part(action->surfaces[(int)frame], source, size, pos - Vector(action->x_offset, action->y_offset),