Added more documentation and make AnimatedObject support scaling

This commit is contained in:
/nick haya 2022-02-07 15:34:51 +08:00
parent 8a273437d4
commit b3cca999d7
2 changed files with 20 additions and 2 deletions

View file

@ -88,6 +88,7 @@ void Render::AnimatedObject::Draw(float dt) {
Render::Object::Draw(dt);
if (current_framename != "") {
// this will make it so that current_frame will only advance when it needs to
int frameToDraw = ((SDL_GetTicks() - startTime) * framerate / 1000) % frameRects[current_framename].size();
current_frame = frameToDraw;
@ -96,9 +97,11 @@ void Render::AnimatedObject::Draw(float dt) {
int sw = frameRects[current_framename][current_frame].w;
int sh = frameRects[current_framename][current_frame].h;
_sc_w = frameRects[current_framename][current_frame].w;
_sc_h = frameRects[current_framename][current_frame].h;
// support scaling :)
_sc_w = frameRects[current_framename][current_frame].w*scale.x;
_sc_h = frameRects[current_framename][current_frame].h*scale.y;
// after setting shit up, we then store it in src_rect.
src_rect = {sx, sy, sw, sh};
}
}

View file

@ -44,6 +44,9 @@ namespace Render {
int id = NULL;
/*
* Create a new Object instance.
*/
void create(int x = 0, int y = 0, string path = "");
virtual void Draw(float dt);
@ -65,6 +68,9 @@ namespace Render {
SDL_Rect src_rect = {0, 0, 0, 0};
/*
* Center object on the center of the screen on a certain axis. Defaults to both X and Y.
*/
void centerSelf(AXIS axis = XY);
private:
int _x, _y, _w, _h;
@ -75,8 +81,17 @@ namespace Render {
class AnimatedObject : public Object {
public:
/*
* Create a new AnimatedObject instance.
*/
void create(int x = 0, int y = 0, string path = "");
/*
* Add an animation to said object. Uses SDL_Rects for frames.
*/
void AddAnimation(string anim_name, vector<SDL_Rect> points);
/*
* Play an animation.
*/
void PlayAnimation(string anim_name);
virtual void Draw(float dt);