Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


SDL Event Handling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 nyl2000   Members   -  Reputation: 129

Like
0Likes
Like

Posted 09 May 2012 - 08:46 PM

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.

Attached Files


Edited by nyl2000, 09 May 2012 - 08:48 PM.


Sponsor:

#2 Oberon_Command   Crossbones+   -  Reputation: 1932

Like
0Likes
Like

Posted 09 May 2012 - 08:51 PM


 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;
            }


#3 Spirrwell   Members   -  Reputation: 271

Like
0Likes
Like

Posted 11 May 2012 - 02:12 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS