here is my main.cpp
#include <iostream>
#include <string>
#include "SDL.h"
#include "gState.h"
gState gameState;
using namespace std;
int main(int argc, char* args[] )
{
if( gameState.init() == false)
{
return 1;
}
gameState.run(1);
gameState.update();
return 0;
}
here is my gState.h
//Player header
#ifndef gSTATE_H
#define gSTATE_H
//includes
#include "gButton.h"
#include "gTimer.h"
#include "gButton.h"
#include <vector>
//Using namespace
//body
class gState{
private:
//Make a vector buttons
std::vector<gButton> buttons;
SDL_Surface *screen;
SDL_Event event;
gTimer fps;
int screenWidth;
int screenHeight;
int frameRate;
int currentState;
bool quit;
public:
gState();
void run(int state);
bool init();
int update();
bool rtnQuit(){return quit;}
};
//end body
#endif
and my gState.cpp
#include "gState.h"
gState::gState(){
}
bool gState::init()
{
quit = false;
frameRate = 60;
screen = NULL;
screenWidth = 1024;
screenHeight = 768;
if (SDL_Init( SDL_INIT_EVERYTHING) == -1)
{
return false;
}
screen = SDL_SetVideoMode(screenWidth, screenHeight, 32, SDL_SWSURFACE /*| SDL_FULLSCREEN*/);
if (screen == NULL)
{
return false;
}
SDL_WM_SetCaption("Phor V0.1", NULL);
return true;
}
void gState::run(int state)
{
currentState = state;
gButton newBtn(100,100,96,32);
buttons.push_back(newBtn);
}
int gState::update()
{
while (rtnQuit() == false)
{
fps.start();
//Event checker
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
quit = true;
}
buttons.at(0).handleEvents(event);
}
SDL_BlitSurface(buttons.at(0).draw(),NULL,screen,&buttons.at(0).rtnPos());
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format,111,206,205));
if (SDL_Flip(screen) == -1)
{
return 1;
}
if( fps.rtnTicks() < 1000 / frameRate )
{
SDL_Delay( ( 1000 / frameRate ) - fps.rtnTicks() );
}
}
}
now when i run my code i get my window correct but the button doesnt come up, now i looked at the size of my vector and its like 400000 and my currentState isn't set to 1, its like set to 1281236, anyone know why its like picking up memory locations?
Canvas