wow sfml has a nice community.thanks for all the help. I finally got an animation class. I based it off the one above.
using namespace std;
class Animation : public sf::Sprite {
public:
Animation(string location,int numFrames,float Delay);
void setCurrentFrame(int frame);
int getCurrentFrame();
void setNumOfFrames(int frames);
int getFrameWidth();
void setDelay();
int getDelay();
void play();
void update();
void pause();
void reset();
private:
sf::Image image;
sf::Clock timer;
int currentFrame;
int numOfFrames;
int frameWidth;
float frameTime;
};
Animation::Animation(string location,int numFrames,float Delay) {
if (!image.LoadFromFile(location))
std::cout<<"unable to load from "<<location;
SetImage(image);
currentFrame=1;
numOfFrames=numFrames;
frameWidth=GetSize().x/numOfFrames;
frameTime=Delay;
SetSubRect(sf::IntRect(0,0,frameWidth,GetSize().y));
}
void Animation:: setCurrentFrame(int frame) {
currentFrame=frame;
}
int Animation::getCurrentFrame() {
return currentFrame;
}
void Animation::setNumOfFrames(int frames) {
numOfFrames=frames;
}
int Animation:: getFrameWidth() {
return frameWidth;
}
void Animation::play() {
SetSubRect(sf::IntRect((currentFrame-1)*frameWidth,0,currentFrame*frameWidth,GetSize().y));
}
void Animation::update() {
if (timer.GetElapsedTime() >= frameTime) {
if (++currentFrame > (numOfFrames))
currentFrame = 1;
timer.Reset();
}
}
(ignore all the useless functions)