New to c++, I'm trying to make a simple start screen for a video game. I want the start screen to scroll in from the bottom of the screen. In order to do this, I have some member variables that are accessed in a function called Update. The problem I am having is that I initialize scrollStart
in a constructor with non-zero values. However, when Update
is called, I print out the y-value of scrollStart
and it is 0
. There is only one other member function in this class that doesn't touch scrollStart
so I have no Idea why it is getting reset to zero. Does anyone more familiar with c++ have any ideas why this would be happening?
My header file likes something like this (irrelevant things removed):
class StartScreen : public GameEntity
{
private:
Vector2 scrollStart;
public:
void Update();
};
My cpp file looks something like this:
StartScreen::StartScreen()
{
...
Vector2 scrollStart = Vector2(SCREEN_WIDTH*0.5f, SCREEN_HEIGHT);
printf("scrollStart Y: %f\n", scrollStart.y); // prints 868 as it should
}
StartScreen::Update()
{
printf("scrollStart Y: %f\n", scrollStart.y); // prints 0
}