GoDucks713
GoDucks713

Reputation: 61

error C2065: 'frame' : undeclared identifier

So I'm working through a beginning game programming book using C++ and visual studio and I'm having issues with an apparent global variable frame, and starttime not being declared.

Here is the header

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

Here is the cpp file that defines the function

//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;
    }
}

and the other cpp file where I'm getting the error

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

I'm getting this in my error output:

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

If you need any more info just let me know.

Upvotes: 1

Views: 965

Answers (1)

songyuanyao
songyuanyao

Reputation: 172924

You need to declare the variable first:

int frame;
int starttime;

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

Upvotes: 1

Related Questions