SFML community forums
Help => General => Topic started by: Kamaitachi on March 16, 2011, 01:20:26 pm
-
:( Another problem came up. The following (I believe) piece of code isn't drawing anything. What is wrong this time?
void Field::FDisplay (float pos1, float pos2, int pl)
{
for(int i = 0; i < 3; i++)
{
if (Farray[i] != 0 && Farray[i] != 1)
{
Farray[i] = 0;
}
}
App.Clear();
sprite[1].SetX(0.f);
sprite[1].SetY(0.f);
App.Draw(sprite[1]); //Corrected
}
//...
F.FDisplay(1.f, 1.f, 1);
-
Did you forgot App.Display() / Clear() ?
-
Added App.Display, as following:
App.Clear();
sprite[1].SetX(pos1);
sprite[1].SetY(pos2);
App.Draw(sprite[1]);
App.Display();
Still not drawing anything.[/code]
-
That code snippet is not very helpful. What's in the sprite array, especially sprite[0]? How got it initialized? Why do you set the position for sprite[1] but draw sprite[0]?
-
Okay:
1- sprite[0] contain a black and white sprite (the background).
2- They were initialized with the following code:
void Field::FDImage(std::string filename, int arpos)
{
if(!image[arpos].LoadFromFile(filename))
{
App.Close();
}
sprite[arpos].SetImage(image[arpos]);
}
and
FDImage("Field.bmp", 0);
FDImage("O.bmp", 1);
FDImage("X.bmp", 2);
3- That was an error I corrected already.
-
The image array is valid for all the time the sprites are being used?
-
I think so. The array is initialized before the use of FDisplay, and no function modifies it afterwards.
-
Minimal compilable code that reproduces the problem?
You can't expect us to guess what your code does. :)
-
Found the problem, while "minimizing" the problem:
The order of these two functions:
while(App.IsOpened())
{
FEvent();
FDisplay(1.f, 1.f, 1);
}
Makes it so that FDisplay is never called. If I call FEvent(), FDisplay() isn't called, and nothing is displayed. If FDisplay() is called first (and FEvent() is slightly tweaked, making a FDisplay call), everything works fine. I should have noticed that before... Anyway, thanks for the help!
-
That shouldn't happen. Show us the FEvent code.
-
I'm with devlin: We can't know what all those F-things do, neither it's possible to follow your program flow.
Having two statements next to each other without conditionals and when the second statement is not being executed, there's really something weird going on (might happen due to exceptions of any kind, but you should get noticed about it by program abortions -- at least if you don't catch them).
-
This was FEvent():
void Field::FEvent ()
{
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::MouseButtonPressed)
App.Close();
}
}
}
-
Ehm, of course it never makes it to FDisplay?
You have an infinite loop in FEvent - until your program closes.
-
This was FEvent():
void Field::FEvent ()
{
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::MouseButtonPressed)
App.Close();
}
}
}
void Field::FEvent ()
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::MouseButtonPressed)
App.Close();
}
}
Fixed it.