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

Author Topic: code closes before i can use it  (Read 1696 times)

0 Members and 1 Guest are viewing this topic.

totalwar235

  • Newbie
  • *
  • Posts: 11
    • View Profile
code closes before i can use it
« on: February 18, 2011, 04:11:58 am »
the following code closes before i can even use it. i have no clue what is wrong because the debug does not report any errors when running.

Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

////////////////////////////////////////////////////////////
// Control Center of Functions
////////////////////////////////////////////////////////////
int Mouse_Check(int M_Y,int M_X);

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
sf::Window App(sf::VideoMode(600, 650), "Spanish Game");

    // Load the sprite image from a file
    sf::Image Main_Box;
    if (!Main_Box.LoadFromFile("Main_Box.bmp"))
        return EXIT_FAILURE;

// Load the sprite image from a file
    sf::Image Answer_Box;
    if (!Answer_Box.LoadFromFile("Answer_Box.bmp"))
        return EXIT_FAILURE;

// Load the sprite image from a file
    sf::Image Roll_Over;
    if (!Roll_Over.LoadFromFile("Roll_Over.bmp"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Main(Main_Box);
sf::Sprite Answer_One(Answer_Box);
sf::Sprite Answer_Two(Answer_Box);
sf::Sprite Answer_Three(Answer_Box);
sf::Sprite Answer_Four(Answer_Box);

    // Change its properties
    Main.SetPosition(100.f, 0.f);
Answer_One.SetPosition(100.f, 200.f);
Answer_Two.SetPosition(300.f, 200.f);
Answer_Three.SetPosition(100.f, 350.f);
Answer_Four.SetPosition(300.f, 350.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }
//Mouse Locations
const sf::Input& Input = App.GetInput();

int M_Y = App.GetInput().GetMouseY();
int M_X = App.GetInput().GetMouseX();

int Change = Mouse_Check(M_Y,M_X);
if(Change == 1)
{
sf::Sprite Answer_One(Roll_Over);
}
if(Change == 2)
{
sf::Sprite Answer_Two(Roll_Over);
}
if(Change == 3)
{
sf::Sprite Answer_Three(Roll_Over);
}
if(Change == 4)
{
sf::Sprite Answer_Three(Roll_Over);
}//replaces image for the roll over effect

// Clear the window
        //App.Clear();

// Display things on screen
        App.Display();

    }

    return EXIT_SUCCESS;
}



int Mouse_Check(int M_Y,int M_X)
{
int X = 0, Y = 0;
//used to check all positions to see if your mouse is over a location
for(X++; X<150;)
{
for(Y++; Y<200;)
{
Y += 200;
X += 100;
if((X == M_X)&&(Y==M_Y))
{
return 1;
}
X += 200;
if((X==M_X)&&(Y==M_Y))
{
return 2;
}
Y += 150;
X -= 200;
if((X==M_X)&&(Y==M_Y))
{
return 3;
}
X +=200;
if((X==M_X)&&(Y==M_Y))
{
return 4;
}

X-=300;
Y-=350;
}
}//end of X and Y checks
return 0;
}


does anyone know what is wrong?

Gibgezr

  • Newbie
  • *
  • Posts: 33
    • View Profile
code closes before i can use it
« Reply #1 on: February 18, 2011, 05:42:46 am »
At a guess, I would say it may not be loading one of the graphic files correctly...check and make sure they exist, are named correctly etc.

To find the problem, you should just follow standard debugging practice: run your program from a debugger in step mode, and step line by line through the code until it exits...that should show you WHERE it is exiting, which will probably tell you WHY it is exiting. Again, my first geuss is it is returning early because it isn't loading a graphic file, a common mistake.

totalwar235

  • Newbie
  • *
  • Posts: 11
    • View Profile
code closes before i can use it
« Reply #2 on: February 19, 2011, 05:59:33 am »
You were right. I misplaced the image