SFML community forums
Help => Graphics => Topic started by: led on April 23, 2010, 01:06:25 am
-
Hey,
In my project I have 3 Main screens: Menu, The game itself and ScoreBoard.
Now the problem is that when i run the Scoreboard function which draws the ScoreBoard, I noticed that the condition 'Event.Type == Event::Closed' is executed while I didn't close the Window. But with the Menu it doesn't happen.
Any sugestions?
bool Menu(sf::RenderWindow &Window);
bool ScoreBoard(sf::RenderWindow &Window);
if (ScoreBoard(Window))
return 0;
if (Menu(Window))
return 0;
//both Menu and ScoreBoard Event loop
while (Window.GetEvent(Event));
{
gui.ProcessKeys(&Event); //only ScoreBoard has this line
if (Event.Type == Event::Closed)
return true;
}
-
My first instinct says that gui::ProcessKeys() does something to Event...
-
Nop, it isnt because of that line, i commented that line and still the same problem. Well i did a breakpoint in the initialization of the Event variavel and its skips the init., and the Event.Type is Closed while i did nothing. :oops:
-
Can you show more code of this part ?
and some code of other (menu and game) ?
-
Here it goes
Main.cpp
cp::cpGuiContainer gui;
cp::cpButton buttonok(&Window, &gui, "Aceitar", (input.GetPosition().x + (input.GetSize().x / 2) - 50 ), (input.GetPosition().y + input.GetSize().y + 10), 100, 50);
if(buttonok.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
player1.Nick = input.GetLabelText();
Window.ShowMouseCursor(true);
if (ScoreBoard(Window))
return 0;
if (Menu(Window))
return 0;
Initialize(balloon, object, hand, time, player1.SScore, player1.Score, buttonok, input);
}
Menu.cpp
while (Window.IsOpened())
{
Event Event;
//Update
while (Window.GetEvent(Event));
{
if (Event.Type == Event::Closed)
return true;
...
}
}
ScoreBoard.cpp
cp::cpGuiContainer Gui;
cp::cpButton button1(&Window, &Gui, "MENU", 512 - 42, 600, 100, 50);
cp::cpButton button2(&Window, &Gui, "FTP", 600, 600, 100, 50);
//main loop
while (Window.IsOpened())
{
Event Event;
//Update
while (Window.GetEvent(Event));
{
//Gui.ProcessKeys(&Event);
if (Event.Type == Event::Closed)
return true;
}
if(button1.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
return false;
}
if(button2.CheckState(&Window.GetInput()) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
{
FTPserver();
}
}
-
Why Event.Type is Closed after being initialized?
-
while (Window.GetEvent(Event));
What is that semicolon at the end of the line? ;)
-
LOL, Epic Mistake :lol:
I had that error in the Menu, and the same happened to him when i call him in the game loop.
Sorry for this stupid error, i didn't noticed it :roll:
Thank you very much :D :wink:
-
Second thing, if I were you I will really not use such a CamelCase with those names : Event and Event, it can be very confusing ;)
-
Sorry for this stupid error, i didn't noticed it :roll:
Thank you very much :D :wink:
We are all humans :D
And I agree to Mindiell. Well, there are a lot of naming conventions out there. http://geosoft.no/development/cppstyle.html This is the one I use (except that private members have a "my... " prefix instead), but feel free to google yourself one ;) It really improves readability, so it is more likely other programmers will help you. Good luck on the project ;)
(Btw, this CamelCase appears in SFML tutorials, I guess led took from there... am I right?)
-
Yes your right :wink: