This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Tortuga/client/sprite_sheet.cpp
T
2013-04-29 17:25:56 +10:00

27 lines
757 B
C++

#include "sprite_sheet.h"
SpriteSheet::SpriteSheet(SDL_Surface* s, Uint16 w, Uint16 h)
: Image(s, {0, 0, w, h})
{
currentFrame = 0; maxFrames = GetSurface()->w / GetClipW();
currentStrip = 0; maxStrips = GetSurface()->h / GetClipH();
interval = ticks = 0;
}
void SpriteSheet::Update(int delta) {
if (interval && (ticks += delta) > interval) {
if (++currentFrame >= maxFrames) {
currentFrame = 0;
}
ticks = 0;
}
SetClipX(currentFrame * GetClipW());
SetClipY(currentStrip * GetClipH());
}
void SpriteSheet::SetSurface(SDL_Surface* s, Uint16 w, Uint16 h) {
Image::SetSurface(s, {0, 0, w, h});
currentFrame = 0; maxFrames = GetSurface()->w / GetClipW();
currentStrip = 0; maxStrips = GetSurface()->h / GetClipH();
interval = ticks = 0;
}