mirror of
https://github.com/haya3218/SDfmL.git
synced 2024-08-14 23:57:09 +00:00
Added more documentation and make AnimatedObject support scaling
This commit is contained in:
parent
8a273437d4
commit
b3cca999d7
2 changed files with 20 additions and 2 deletions
|
@ -88,6 +88,7 @@ void Render::AnimatedObject::Draw(float dt) {
|
||||||
Render::Object::Draw(dt);
|
Render::Object::Draw(dt);
|
||||||
|
|
||||||
if (current_framename != "") {
|
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();
|
int frameToDraw = ((SDL_GetTicks() - startTime) * framerate / 1000) % frameRects[current_framename].size();
|
||||||
current_frame = frameToDraw;
|
current_frame = frameToDraw;
|
||||||
|
|
||||||
|
@ -96,9 +97,11 @@ void Render::AnimatedObject::Draw(float dt) {
|
||||||
int sw = frameRects[current_framename][current_frame].w;
|
int sw = frameRects[current_framename][current_frame].w;
|
||||||
int sh = frameRects[current_framename][current_frame].h;
|
int sh = frameRects[current_framename][current_frame].h;
|
||||||
|
|
||||||
_sc_w = frameRects[current_framename][current_frame].w;
|
// support scaling :)
|
||||||
_sc_h = frameRects[current_framename][current_frame].h;
|
_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};
|
src_rect = {sx, sy, sw, sh};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ namespace Render {
|
||||||
|
|
||||||
int id = NULL;
|
int id = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new Object instance.
|
||||||
|
*/
|
||||||
void create(int x = 0, int y = 0, string path = "");
|
void create(int x = 0, int y = 0, string path = "");
|
||||||
|
|
||||||
virtual void Draw(float dt);
|
virtual void Draw(float dt);
|
||||||
|
@ -65,6 +68,9 @@ namespace Render {
|
||||||
|
|
||||||
SDL_Rect src_rect = {0, 0, 0, 0};
|
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);
|
void centerSelf(AXIS axis = XY);
|
||||||
private:
|
private:
|
||||||
int _x, _y, _w, _h;
|
int _x, _y, _w, _h;
|
||||||
|
@ -75,8 +81,17 @@ namespace Render {
|
||||||
|
|
||||||
class AnimatedObject : public Object {
|
class AnimatedObject : public Object {
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
|
* Create a new AnimatedObject instance.
|
||||||
|
*/
|
||||||
void create(int x = 0, int y = 0, string path = "");
|
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);
|
void AddAnimation(string anim_name, vector<SDL_Rect> points);
|
||||||
|
/*
|
||||||
|
* Play an animation.
|
||||||
|
*/
|
||||||
void PlayAnimation(string anim_name);
|
void PlayAnimation(string anim_name);
|
||||||
virtual void Draw(float dt);
|
virtual void Draw(float dt);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue