C无法增加变量
我正在为一个小型游戏引擎开发一个动画类,由于某种原因,帧计数器不想增加,它会一直停留在0或1.
这是Animation :: Step代码(这里应该发生增量):
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...
...
}
现在这是调用Animation :: Step的部分:
inline void DrawAnimation(Animation ani, Vec2 pos, BlendMode mode, DrawTextureAttributes attr)
{
ani.Step();
...
// draw texture
}
并在游戏主循环中:
void on_render(Renderer r)
{
DrawTextureAttributes attr;
attr.Scale = Vec2(1.5);
r.DrawAnimation(ani, Vec2(320, 240), BlendMode::Normal, attr);
}
编辑:类定义:
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;
};
好的,先谢谢! (抱歉我的英语不好)