-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Animations for Elements, fix texture width
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "Animation.hpp" | ||
#include "./DrawUtils.hpp" | ||
|
||
Animation::Animation(int startTime, int duration, std::function<void(float)> onStep, std::function<void()> onFinish) { | ||
this->startTime = startTime; | ||
this->duration = duration; | ||
this->onStep = onStep; | ||
this->onFinish = onFinish; | ||
} | ||
|
||
bool Animation::isFinished() { | ||
return CST_GetTicks() > startTime + duration; | ||
} | ||
|
||
bool Animation::step() { | ||
if (isFinished()) { | ||
onFinish(); | ||
return true; | ||
} | ||
|
||
if (onStep != NULL) { | ||
float progress = (float)(CST_GetTicks() - startTime) / (float)duration; | ||
onStep(progress); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include <functional> | ||
|
||
class Animation | ||
{ | ||
public: | ||
Animation(int startTime, int duration, std::function<void(float)> onStep, std::function<void()> onFinish); | ||
|
||
bool isFinished(); | ||
bool step(); | ||
int startTime = 0; | ||
int duration = 0; | ||
std::function<void(float)> onStep = NULL; | ||
std::function<void()> onFinish = NULL; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters