program HowToAllowTheUserToCloseTheWindow; uses SwinGame; procedure Main(); begin OpenGraphicsWindow('How To Allow The User To Close The Window' ,800 ,600 ); LoadDefaultColors(); repeat ProcessEvents(); ClearScreen(ColorWhite ); DrawText('Close the window' ,ColorBlack ,0 ,0 ); RefreshScreen(); until WindowCloseRequested(); end; begin Main(); end.
How to allow the user to close the Window
This how to shows how to listen to see if the user has closed the window. This demonstrates the core SwinGame input functions and procedures.
In most games you will want the game screen to continue to be displayed until the game ends, or the user closes the window. To achieve this in your game you need to start using SwinGame's input functionality.
At the core of SwinGame's input is the Process Events procedure. This procedure listens to user input, and records what has happened. You can then query SwinGame to check what the user has done.
If you want to check if the user has asked to close the window use the Window Close Requested function. This will return true when the user has tried to close the window.
Each time you call Process Events SwinGame will clear its current list of actions, and check what the user has perfumed since the last call to Process Events. Try to only call Process Events once in your main loop.
The code below shows a small program that demonstrates these input operations in action. The program will continue to show the game screen to the user until they ask to close the window. This is the standard sequence of operations you would expect to see in SwinGames.