i thought maybe the problem is that the data is used by virtual and non virtual functions,and that when in one or the other the data members are created newly in that scope, no idea, i dont know, like i say its crazy because one array of elements remains ok,
its probably best with some code then >>
here is the class definition, defined in MenuState.h
Code:
class MenuState : public StateEngine
{
private:
SDL_Surface* Buttonsource;
SDL_Rect menubutton[6]; //this is the array of structs that automagically change
SDL_Rect menuclip[6];
SDL_Rect playarea[2]; //collison boxes to check for change of state, these values stay ok after initialisation
int count;
int lastbutton;
int testX, testY;
public:
void HandleEvents(); //these 3 are the only shared functions in the virtual base class
void Do_Logic();
void Render();
void InitButtons(); //this is not in the base class ...perhaps it should be private??
MenuState();
~MenuState();
};
here is the constructor in the MenuState.cpp file
Code:
MenuState::MenuState()
{
temp = NULL; //this is global
Buttonsource = NULL;
temp = SDL_LoadBMP("buttonsheet.bmp");
Buttonsource = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
count = 0;
lastbutton = 10;
testX = 0;
testY = 0;
InitButtons();
}
and here is the definition of InitButtons(); from the same file
Code:
void MenuState::InitButtons()
{
int Ypos = 200;
for(count = 0; count < 6; count++)
{
menubutton[count].x = 673; menubutton[count].y = Ypos; //attributes of normal size buttons
menubutton[count].w = 196; menubutton[count].h = 83;
Ypos += 100;
if(count == 3) //sort out width height and position of the two smaller save and load buttons
{
menubutton[count].x = 690;
menubutton[count].y = 511;
}
if(count == 4)
{
menubutton[count].x = 775;
menubutton[count].y = 511;
Ypos -= 100; // pull value back or it will miss the next button (bc ypos will= 700 and 600 is max)
}
if(count == 3 || count == 4)
{
menubutton[count].w = 75;
menubutton[count].h = 60;
}
}
for(count = 0; count < 2; count++) //Set the size of the collision boxes...(these values remain ok after initialising)
{
if(count == 0)
{
playarea[count].x = 210; playarea[count].y = 120;
playarea[count].w = 210; playarea[count].h = 290;
}
if(count == 1)
{
playarea[count].x = 110; playarea[count].y = 235;
playarea[count].w = 420; playarea[count].h = 175;
}
}
}