PDA

View Full Version : SDL C++ drawing problem


gardon
03-16-2006, 03:26 PM
I'm having a problem drawing to the screen based on gameStates. I'm not a noob, and this is a serious problem that I can't spend any more time slaving over.

The program runs like this:

while (menu->IsRunning()) // which returns true until the prog exits
{
Poll for input;

switch (g_globalState) // initially set to MENU above
{
case Menu:
g_globalState = Menu->Run() // which returns the global state
// after updating Menu
case GAMELOOP;
g_globalState = Engine->Run() // which does the same thing
}
}


-- end sample


So each frame it updates itself and checks for the globalState, which in turns either goes through Menu or Engine->Run(). once I Set the globalSTate to GAMELOOP through Menu options (I.e I click on the new game button) it goes to engine.

The problem I'm having is trying to get back to menu. I set the escape key to revert me back (setting globalSTate to MENU), which should run the MENU function and update it, however, it brings it back to menu but consistently draws and updates GAMELOOP as well.

It's like the switch statement doesn't matter, and it's still updating engine, which causes a double overlap of time and animation..,

I'm using double buffering, but that shouldn't make a difference.

Thanks,

Jason


And if you guys have visual studio and wanna check it out, go here: <a href="http://massive-war.com/Demo.rar">Here</a>

.oisyn
03-16-2006, 04:41 PM
You forgot the break statement at the end of the MENU case. Read the C++ documentation about how to use the switch statement.

gardon
03-16-2006, 07:44 PM
which MENU case? in maiN? there's a break statement there

gardon
03-16-2006, 07:47 PM
and that documentation looks fine to me:

switch(variable)
{
case whatever: break;
case whatever2: break;
case whatever4: break;
default: break;
}

Reedbeta
03-16-2006, 11:41 PM
Well, the code in your original post doesn't have the break statement.

gardon
03-17-2006, 12:21 PM
But it's fixed now, and the problem still arises.

Ugh

Reedbeta
03-17-2006, 02:40 PM
Have you tried stepping through with a debugger to see exactly what happens when the game is in the menu state?

gardon
03-17-2006, 04:44 PM
Yes, and I still can't figure it out.

God, I don't know what the problem is, but Im' sure I"ll figure it out sooner or later

Jason Otto