Sprite::set_frame(int) crops frame numbers that are out of range.
Sprite::check_animation() renamed to Sprite::animation_done().
SVN-Revision: 3069
}
bool
-Sprite::check_animation()
+Sprite::animation_done()
{
return animation_loops == 0;
}
void
Sprite::update()
{
- if(animation_loops == 0)
+ if(animation_done())
return;
Uint32 ticks = SDL_GetTicks();
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;
}
}
void stop_animation()
{ animation_loops = 0; }
/** Check if animation is stopped or not */
- bool check_animation();
+ bool animation_done();
float get_fps() const
{ return action->fps; }
int get_frame() const
{ return (int)frame; }
/** Set current frame */
- void set_frame(int frame_)
- { if(frame_ > get_frames()) frame = 0; else frame = frame_; }
+ void set_frame(int frame)
+ {
+ this->frame = (frame % get_frames());
+ }
Surface* get_frame(unsigned int frame)
{
assert(frame < action->surfaces.size());
Door::update(float )
{
//Check if door animation is complete
- if(sprite->check_animation()) {
+ if(sprite->animation_done()) {
sprite->set_action("normal");
GameSession::current()->respawn(target_sector, target_spawnpoint);
}
Hatch::update(float )
{
//Check if hatch animation is complete
- if(sprite->check_animation()) {
+ if(sprite->animation_done()) {
sprite->set_action("normal");
GameSession::current()->respawn(target_sector, target_spawnpoint);
}