C++ 无法递增变量
C++ Can't increment a variable
我正在为一个小型游戏引擎开发一个动画类,由于某种原因,帧计数器不想增加,它一直停留在 0 或 1。
这是动画::步骤代码(这是应该发生增量的地方):
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...
...
}
现在这是调用动画::步骤的部分:
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;
};
好吧,提前谢谢!(对不起,我的英语有点不好)
inline void DrawAnimation(Animation ani...
每次按值将对象传递给此函数时。因此,任何增量都将应用于此副本,而不是您的原始值。可以通过引用传递以获取所需的行为。
inline void DrawAnimation(Animation& ani...
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 尝试通过多个向量访问变量时,向量下标超出范围
- 试图让变量检查数组中的某些内容
- Cpp-Tuple使用带有变量的get
- 将包含C样式数组的对象初始化为成员变量(C++)
- 当vector是tje全局变量时,c++中vector的内存管理
- 通过多个头文件使用常量变量
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 执行函数时导致崩溃的变量
- 变量没有改变?通过向量的函数调用