-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationComponent.cpp
More file actions
54 lines (42 loc) · 1.17 KB
/
AnimationComponent.cpp
File metadata and controls
54 lines (42 loc) · 1.17 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "AnimationComponent.h"
#include "PhysicsComponent.h"
AnimationComponent::AnimationComponent(ResourceManager* resourceHandle,
string animationResourceID)
: Component(ComponentType::ANIMATION),
resourceHandle(resourceHandle),
animationResourceID(animationResourceID)
{
animationResource = resourceHandle->getAnimation(animationResourceID);
frameIndex = 0;
currentFrameTime = 0.0f;
}
AnimationComponent::~AnimationComponent()
{
}
void AnimationComponent::update(float dt)
{
// Add time to the animation
currentFrameTime += dt;
if (currentFrameTime >= animationResource->getFrameDuration(frameIndex))
{
// If we exceed the frame duration, move on to the next frame
currentFrameTime = 0.0f;
frameIndex++;
// If we overshoot, move the index to the beginning (0) instead.
if (frameIndex == animationResource->getFrameCount())
{
frameIndex = 0;
}
}
}
void AnimationComponent::draw()
{
PhysicsComponent* p;
p = (PhysicsComponent*)getComponent(ComponentType::PHYSICS);
animationResource->draw(frameIndex, p->getx(), p->gety());
}
void AnimationComponent::applyBuffer()
{
//Do nothing
//Eventually this will buffer changes to the Animation state.
}