Okay, so I’m calling a function that draws three lines to display an ‘I’ on-screen.
Then, I call another function which calls this function, but adds 1 to the x variable to
make a the letter bold. Then I want to put x++ add in the ‘tick’ function, which executes
every frame. It isn’t working, but why? If you don’t understand what I mean, please check this page, it’s the tutorial I’m following: http://www.devmaster.net/articles/intro-to-c++-with-game-dev/part3.php
Declare global x and y and call function tick:
int x = 0;
int y = 0;
void Game::Tick( float a_DT )
{
m_Screen->Clear( 80 );
DrawI(0,0);
x++;
}
Making functions:
void Game::DrawI(int x, int y)
{
m_Screen->Line( 100 + x, 50 + y, 200 + x, 50 + y, 0xffffff );
m_Screen->Line( 150 + x, 50 + y, 150 + x, 300 + y, 0xffffff );
m_Screen->Line( 100 + x, 300 + y, 200 + x, 300 + y, 0xffffff );
}
void Game::DrawFatI()
{
DrawI(1,0);
DrawI(0,1);
DrawI(0,0);
DrawI(1,1);
}
Thanks for checking.
When you call DrawI it has
xandypassed to it as parameters:These mask the global
xandy, such that withinDrawIeverywhere you sayxandyit refers to the function parameters. (You can access the global ones using::xand::ythough).Since you always call
DrawIwith literals, not variables, e.g.DrawI(1,0);the values ofxandyinDrawInever change, they are always just these fixed values and not the global variable, henceLineis always passed the same values, even if your globalxhas changed.I would make two recommendations to avoid this: