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

Author Topic: App.Draw() trouble  (Read 4248 times)

0 Members and 2 Guests are viewing this topic.

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« 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?

Code: [Select]
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);

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
App.Draw() trouble
« Reply #1 on: March 16, 2011, 01:36:57 pm »
Did you forgot App.Display() / Clear() ?
Pointilleur professionnel

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« Reply #2 on: March 16, 2011, 02:08:09 pm »
Added App.Display, as following:

Code: [Select]
   App.Clear();

    sprite[1].SetX(pos1);
    sprite[1].SetY(pos2);
    App.Draw(sprite[1]);

    App.Display();


Still not drawing anything.[/code]

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
App.Draw() trouble
« Reply #3 on: March 16, 2011, 02:32:56 pm »
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]?

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« Reply #4 on: March 16, 2011, 02:48:05 pm »
Okay:
1- sprite[0] contain a black and white sprite (the background).
2- They were initialized with the following code:

Code: [Select]
void Field::FDImage(std::string filename, int arpos)
{
    if(!image[arpos].LoadFromFile(filename))
    {
        App.Close();
    }
    sprite[arpos].SetImage(image[arpos]);
}


and

Code: [Select]
FDImage("Field.bmp", 0);
    FDImage("O.bmp", 1);
    FDImage("X.bmp", 2);


3- That was an error I corrected already.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
App.Draw() trouble
« Reply #5 on: March 16, 2011, 03:18:48 pm »
The image array is valid for all the time the sprites are being used?

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« Reply #6 on: March 16, 2011, 05:17:09 pm »
I think so. The array is initialized before the use of FDisplay, and no function modifies it afterwards.

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
App.Draw() trouble
« Reply #7 on: March 16, 2011, 05:39:53 pm »
Minimal compilable code that reproduces the problem?

You can't expect us to guess what your code does. :)

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« Reply #8 on: March 16, 2011, 06:32:08 pm »
Found the problem, while "minimizing" the problem:
The order of these two functions:

Code: [Select]
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!

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
App.Draw() trouble
« Reply #9 on: March 16, 2011, 11:22:43 pm »
That shouldn't happen. Show us the FEvent code.
I use the latest build of SFML2

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
App.Draw() trouble
« Reply #10 on: March 17, 2011, 09:16:53 am »
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).

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() trouble
« Reply #11 on: March 20, 2011, 02:18:58 pm »
This was FEvent():

Code: [Select]
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();
        }
    }
}

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
App.Draw() trouble
« Reply #12 on: March 20, 2011, 06:28:44 pm »
Ehm, of course it never makes it to FDisplay?

You have an infinite loop in FEvent - until your program closes.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
App.Draw() trouble
« Reply #13 on: March 21, 2011, 04:13:11 am »
Quote from: "Kamaitachi"
This was FEvent():

Code: [Select]
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();
        }
    }
}
Code: [Select]
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.
I use the latest build of SFML2

 

anything