I'm working on an Animation class for a small game engine, and for some reason the frame counter does not want to increment, it keeps stuck at 0 or 1.
This is the Animation::Step code (here's where the incrementation is supposed to happen):
void Animation::Step()
{
...
time += (float)glfwGetTime();
if (time >= Speed)
{
time = 0;
if (f++ >= count - 1)
{
...
}
}
// Here I do some math to get a clip rectangle...
...
}
Now this is the part where Animation::Step is called:
inline void DrawAnimation(Animation ani, Vec2 pos, BlendMode mode, DrawTextureAttributes attr)
{
ani.Step();
...
// draw texture
}
And in the game mainloop:
void on_render(Renderer r)
{
DrawTextureAttributes attr;
attr.Scale = Vec2(1.5);
r.DrawAnimation(ani, Vec2(320, 240), BlendMode::Normal, attr);
}
EDIT: The class definition:
class Animation
{
public:
Animation() {}
Animation(Texture2D tex, int rows, int cols, int *frames, float speed, bool loop=false);
Animation(Texture2D tex, int rows, int cols, float speed, bool loop=false);
Texture2D Texture;
std::vector<int> Frames;
float Speed;
bool Loop;
float getCellWidth();
float getCellHeight();
void Step();
UVQuad RETUV;
private:
int f, r, c; // here's F
float w, h;
float time;
};
Well, thanks in advance! (and sorry for my kinda bad english)
inline void DrawAnimation(Animation ani...
Each time you pass object by value to this function. So, any increment would be applied to this copy rather than your original value. You can pass by reference to get the desired behavior.
inline void DrawAnimation(Animation& ani...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With