This is a very strange phenomenon to me. I have a class definition for a game, but when I add another variable to the class, the draw method does not print everything to the screen. It will be easier understood showing the code and output.
Code for good draw output:
class board
{
protected:
RectangleShape rect;
int top, left;
int i, j;
int rowSelect, columnSelect;
CircleShape circleArr[4][10];
CircleShape codeArr[4];
CircleShape keyArr[4][10];
//int pegPresent[4];
public:
board(void);
void draw(RenderWindow& Window);
int mouseOver(RenderWindow& Window);
void placePeg(RenderWindow& Window, int pegSelect);
};
Screen:
Code for missing draw:
class board
{
protected:
RectangleShape rect;
int top, left;
int i, j;
int rowSelect, columnSelect;
CircleShape circleArr[4][10];
CircleShape codeArr[4];
CircleShape keyArr[4][10];
int pegPresent[4];
public:
board(void);
void draw(RenderWindow& Window);
int mouseOver(RenderWindow& Window);
void placePeg(RenderWindow& Window, int pegSelect);
};
Screen:
And the draw funciton:
void board::draw(RenderWindow& Window)
{
Window.draw(rect);
for(j = 0; j < 10; j++)
{
for(i = 0; i < 4; i++)
{
Window.draw(circleArr[i][j]); //these is the array of the large 4x10 circles
Window.draw(keyArr[i][j]); //this is the problem array
}
}
for(i = 0; i < 4; i++)
{
Window.draw(codeArr[i]); //these are the four circles at the top
}
}
As you can see, all I do is un-comment the protected array and most of the pegs are gone from the right hand side. I have checked and made sure that I didn't accidentally created a variable with that name already. I haven't used it anywhere. Another thing I noticed, it actually draws the four top pegs which come after the missing pegs.
Why does it not draw the remaining pegs as it should?
My only thought is that maybe I am declaring too many variables for the class, but that doesn't really make sense to me. Any thoughts and help is greatly appreciated.
EDIT: I have tried switching the order of the keyArr
and codeArr
and still the same result.
pegPresent
variable wasn't declared so I highly doubt it is a scoping issue. – Josh Nov 6 '13 at 22:43