-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.cpp
More file actions
executable file
·35 lines (32 loc) · 1.01 KB
/
Animation.cpp
File metadata and controls
executable file
·35 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "include/Animation.hpp"
#include <SFML/Graphics.hpp>
using namespace sf;
Animation::Animation(Texture *texture, int frameWidth, int frameHeight, int framesCount, int firstFrameX, int firstFrameY, float animationDelay) : texture(texture), frameWidth(frameWidth), frameHeight(frameHeight), framesCount(framesCount), firstFrameX(firstFrameX), firstFrameY(firstFrameY), delay(animationDelay)
{
sprite.setTexture(*texture);
frameSelection = IntRect(firstFrameX, firstFrameY, frameWidth, frameHeight);
sprite.setTextureRect(frameSelection);
timer = 0;
delay = animationDelay;
}
void Animation::Update()
{
timer++;
if (timer > delay)
{
if (frameSelection.left == firstFrameX + (frameWidth * (framesCount - 1)))
{
frameSelection.left = firstFrameX;
}
else
{
frameSelection.left += frameWidth;
}
sprite.setTextureRect(frameSelection);
timer = 0;
}
}
Sprite &Animation::getSprite()
{
return sprite;
}