Sprite::Sprite(SpriteData& newdata)
: data(newdata), frame(0), animation_loops(-1)
{
- action = data.actions.begin()->second;
+ action = data.get_action("normal");
+ if(!action)
+ action = data.actions.begin()->second;
last_ticks = SDL_GetTicks();
}
return;
SpriteData::Action* newaction = data.get_action(name);
- if(!action) {
+ if(!newaction) {
#ifdef DEBUG
std::cerr << "Action '" << name << "' not found.\n";
#endif
bool
Sprite::check_animation()
{
- return animation_loops;
+ return animation_loops == 0;
}
void
frame += frame_inc;
- float lastframe = frame;
- frame = fmodf(frame+get_frames(), get_frames());
- if(frame != lastframe) {
- if(animation_loops > 0) {
- animation_loops--;
- if(animation_loops == 0)
- frame = 0;
- }
+ if(frame >= get_frames()) {
+ frame = fmodf(frame+get_frames(), get_frames());
+
+ animation_loops--;
+ if(animation_loops == 0)
+ frame = 0;
}
}
}
-/* EOF */