c++ - 错误 C2065 : 'frame' : undeclared identifier

标签 c++ visual-studio-2013 directx-9

所以我正在使用 C++ 和 visual studio 阅读一本游戏编程入门书,但我遇到了一个明显的全局变量框架的问题,并且开始时间没有被声明。

这是标题

void Sprite_Animate(int &frame, int startframe, int endframe, int direction, int &starttime, int delay);

这里是定义函数的cpp文件

//Animates a sprite
void Sprite_Animate(int &frame, int startframe, int endframe, int direction, int &starttime, int delay)
{
    if ((int)GetTickCount() > starttime + delay)
    {
        starttime = GetTickCount();

        frame += direction;
        if (frame > endframe) frame = startframe;
        if (frame < startframe) frame = endframe;
    }
}

和我遇到错误的其他 cpp 文件

//animate and draw the sprite
Sprite_Animate(frame, 0, 24, 1, starttime, 30);

我在我的错误输出中得到这个:

Error   1   error C2065: 'frame' : undeclared identifier    c:\users\foster\documents\visual studio 2013\projects\animate sprite demo\animate sprite demo\mygame.cpp    50  1   Animate Sprite Demo
Error   2   error C2065: 'starttime' : undeclared identifier    c:\users\foster\documents\visual studio 2013\projects\animate sprite demo\animate sprite demo\mygame.cpp    50  1   Animate Sprite Demo
Error   3   error C2065: 'frame' : undeclared identifier    c:\users\foster\documents\visual studio 2013\projects\animate sprite demo\animate sprite demo\mygame.cpp    51  1   Animate Sprite Demo

如果您需要更多信息,请告诉我。

最佳答案

需要先声明变量:

int frame;
int starttime;

//animate and draw the sprite
Sprite_Animate(frame, 0, 24, 1, starttime, 30);

关于c++ - 错误 C2065 : 'frame' : undeclared identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31600866/

相关文章:

javascript - JS Frontend <-> C++后端通信(不同服务器)

c++ - 如何将彩色图像转换为密度单色图像?

c++ - 为什么我的程序会无限循环?

asp.net - NuGet 不断使 Visual Studio 2013 崩溃

c++ - (DirectX) 生成旋转矩阵以匹配 vector

c++ - DirectX 9 "unresolved external symbol"问题

c++ - qml 和 c++ 与 qt quick 2 应用程序

c# - 错误 "The type or namespace name ' DotNetOpenAuth' could not be found"in VS2013 but not not VS2012

Node.js Typescript 包含内容