C无法增加变量

weixin_38071069 2019-09-12 01:32:16
我正在为一个小型游戏引擎开发一个动画类,由于某种原因,帧计数器不想增加,它会一直停留在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; }; 好的,先谢谢! (抱歉我的英语不好)
...全文
17 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38083061 2019-09-12
  • 打赏
  • 举报
回复
inline void DrawAnimation(Animation ani... 每次将对象按值传递给此函数.因此,任何增量都将应用于此副本而不是原始值.您可以通过引用传递以获得所需的行为. inline void DrawAnimation(Animation& ani...

433

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧