Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: window generation between states  (Read 3042 times)

0 Members and 1 Guest are viewing this topic.

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
window generation between states
« on: March 31, 2010, 01:50:36 am »
I'm having problems with generating a window for my gameplay state using C++ and SFML. I'm at a menu screen I select an option and then the window is just frozen. I think somethings wrong with how I'm trying to draw the window since debugging shows that the program is running. Are there any mistakes that you can see?  


This is a skeleton of how the drawing is set up.

Code: [Select]

//playstate.h
sf::RenderWindow Window;

void Draw();

//playstate.cc

void MenuState::Draw()
{
Window.Clear(sf::Color(50, 50, 150));
Window.Draw(BackgroundSprite);
Window.Draw(currentui.UInter);

// Display window contents on screen
Window.Display();
Window.Clear();
}



The menu which precedes the playstate is set up like this

Code: [Select]

//menustate.h


void Draw(sf::RenderWindow &Window);

//menustate.cc

void MenuState::Draw(sf::RenderWindow &Window)
{
Window.Clear(sf::Color(50, 50, 150));
Window.Draw(MenuSprite);
Window.Display();
}




The menu appears to work until I select the play option. I can't set up sf::RenderWindow Window in the playstate like it is in the menu because other functions besides Draw need access to it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
window generation between states
« Reply #1 on: March 31, 2010, 08:47:36 am »
There's nothing wrong here, you should show more code.
Laurent Gomila - SFML developer

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Re: window generation between states
« Reply #2 on: March 31, 2010, 09:10:07 am »
Quote from: "Jarwulf"
I'm at a menu screen I select an option and then the window is just frozen. I think somethings wrong with how I'm trying to draw the window since debugging shows that the program is running.

How can you say the window is frozen ? Is there anything drawn on the window (old menu, new background, anything else) ? If the program is running, isn't there an infinite loop somewhere ?

Can you show us the code about the menu selection ?
Mindiell
----

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: window generation between states
« Reply #3 on: April 01, 2010, 03:57:32 am »
Quote from: "Mindiell"
Quote from: "Jarwulf"
I'm at a menu screen I select an option and then the window is just frozen. I think somethings wrong with how I'm trying to draw the window since debugging shows that the program is running.

How can you say the window is frozen ? Is there anything drawn on the window (old menu, new background, anything else) ? If the program is running, isn't there an infinite loop somewhere ?

Can you show us the code about the menu selection ?




So this is the menu


Code: [Select]

//menustate.cc

void MenuState::OnEvent(MainGame *Game, sf::Event Event)
{
switch(Event.Type)
{
case sf::Event::Closed:
Game->Quit();
break;
case sf::Event::KeyPressed:
switch(Event.Key.Code)
{
case sf::Key::Escape:
// Select Last
mMenu.goLast();
break;
case sf::Key::Up:
mMenu.goUp();
break;
case sf::Key::Down:
mMenu.goDown();
break;
case sf::Key::Return:
switch( mMenu.getSelectedItem() )
{
case 0:
// playState
Game->PushState( PlayState::Instance() );
break;
case 1:
// quit
Game->Quit();
break;
default: break;
}
break;
default: break;
}
break;
default: break;
}
}



case 0 is supposed to lead up to this


Code: [Select]


//playstate.cc


using namespace std;
PlayState PlayState::mPlayState;


void PlayState::OnUpdate(MainGame *Game)
{
//run objects on screen
firsthero.UpdateBoy(Windows.GetInput(), direction, Windows,ObjectArray);
currentui.gameuitrack(firsthero.Mass.GetPosition().x,firsthero.Mass.GetPosition().y);
xydistancefinder(firsthero.Mass.GetPosition().x, View1.GetCenter().x,firsthero.Mass.GetPosition().y, View1.GetCenter().y, distancebetweenxmain, distancebetweenymain,unsignedbx,unsignedby);
 View1.Move( distancebetweenxmain,distancebetweenymain);
Windows.SetView(View1);
}

void PlayState::Draw()
{Windows.Clear();
Windows.Draw(BackgroundSprite);
Windows.Draw(currentui.UInter);
Windows.Display();
Windows.Clear();
}



PlayState *PlayState::Instance()
{
    return &mPlayState;
}



Here is main

Code: [Select]


int main(int argc, char *argv[])
{
 
 MainGame Game("SMEE");

// initialize the engine
if( Game.Init() == false )
{
cout << "[!] Window Created : " << WINWIDTH << "*" << WINHEIGHT << "@" << BPP << " - ERROR" << endl;
return EXIT_FAILURE;
}
cout << "[ ] Window Created : " << WINWIDTH << "*" << WINHEIGHT << "@" << BPP << endl;

// load the intro
Game.ChangeState(MenuState::Instance() );
//Game.ChangeState( CIntroState::Instance() );

// main loop
while(Game.isRunning())
{
Game.OnEvent();

Game.OnUpdate();

Game.OnDraw();
}

// cleanup the engine
Game.Cleanup();
cout << "[ ] Cleanup Success" << endl;

cout << "[ ] Exit Success" << endl;
return EXIT_SUCCESS;
}



when I run debugging I see the program bouncing between playstate::OnUpdate and playstate::Draw so I assume the program must be running but the menu window is still there frozen with playstate selected. I only recently experimented with splitting the program into different states. Before the program was split into different states window generation was handled like this.


Code: [Select]

Int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "WINDOW");


Window.Draw(BackgroundSprite);
}



So I guess in summary I need to know how to get rid of the menu graphics and replace it with the graphics from playstate

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
window generation between states
« Reply #4 on: April 01, 2010, 09:42:02 am »
Since :
Code: [Select]
case 0:
// playState
Game->PushState( PlayState::Instance() );
break;
I think you are using a State Machine, right ?

Can you show us the code of PushState and the code of Game.OnEvent, Game.OnDraw, Game.OnUpdate ?
Mindiell
----

 

anything