Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

enter image description here

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:

enter image description here

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.

share|improve this question

closed as off-topic by Josh Petrie Jun 25 at 15:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
if the issue is with drawing, perhaps you should show the drawing code? –  Chewy Gumball Nov 6 '13 at 22:16
    
I'll put it up, but it doesn't make sense that it will work fine without that one variable. –  Josh Nov 6 '13 at 22:19
    
Why are i and j not scopped to the loops? The way you have it now both loop will only complete once. –  Chewy Gumball Nov 6 '13 at 22:37
    
Both loops complete their proper amount of times. If they didn't then the 4x10 grid of large circles would only contain one row as well which is not the case. Both arrays are in the same loop, so I know the loop is completing correctly. In addition, it completed when the pegPresent variable wasn't declared so I highly doubt it is a scoping issue. –  Josh Nov 6 '13 at 22:43
2  
One of the things I do when debugging SDL is to flip right after a draw and then do a short sleep. This will show each draw step and can help to debug some drawing issues. Also drawing in different colors will indicate where your last draw ocurred. –  UnderscoreZero Nov 7 '13 at 0:08

Browse other questions tagged or ask your own question.