Jump to content
  • Advertisement
Sign in to follow this  
nyl2000

SDL Event Handling

This topic is 2260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently starting out with event handling systems in SDL/C++. I have followed a tutorial to create a simple program that should quit the program when the user X's out/Closes the window.

The program compiles and works as intended, except that the close button does not respond at all when it is clicked. The program stays in its while loop forever, without receiving the command to quit.

I am using a Windows7 Computer, with Codeblocks IDE.
Attached is the program, I am not sure what is preventing me from closing the window at all. Edited by nyl2000

Share this post


Link to post
Share on other sites
Advertisement


if(event.type == SDL_QUIT)
{//SDL_QUIT event type = Closing (Xing Out) Window
quit == true;
}


Should that assignment be a single equals, not a double equals? Otherwise what the program will see is effectively this:




if(event.type == SDL_QUIT)
{//SDL_QUIT event type = Closing (Xing Out) Window
false;
}

Share this post


Link to post
Share on other sites
Oberon_Command is right. It should be quit = true;

Although in the future when you're doing events in SDL, it may be better for you to use a switch statement. If you're not doing many events, an if statement may be all you need, like in this case you're only checking for one in particular, so an if statement is fine. When you have many events, using a switch statement could save you from a lot of problems.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!