From b3cca999d719d527bca6624fdfc11cf7fe41ac70 Mon Sep 17 00:00:00 2001 From: /nick haya <74699483+The-SGPT@users.noreply.github.com> Date: Mon, 7 Feb 2022 15:34:51 +0800 Subject: [PATCH] Added more documentation and make AnimatedObject support scaling --- src/Render.cpp | 7 +++++-- src/Render.hpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Render.cpp b/src/Render.cpp index 45d4a8e..2b0c16d 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -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}; } } diff --git a/src/Render.hpp b/src/Render.hpp index 2b93953..b6cba32 100644 --- a/src/Render.hpp +++ b/src/Render.hpp @@ -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 points); + /* + * Play an animation. + */ void PlayAnimation(string anim_name); virtual void Draw(float dt);