{"id":69,"date":"2017-04-07T12:19:31","date_gmt":"2017-04-07T12:19:31","guid":{"rendered":"http:\/\/www.ruzzgames.com\/?page_id=69"},"modified":"2020-04-18T23:16:18","modified_gmt":"2020-04-18T13:16:18","slug":"game-loop","status":"publish","type":"page","link":"https:\/\/www.ruzzgames.com\/index.php\/game-loop\/","title":{"rendered":"Game Loop"},"content":{"rendered":"<p>Games are real-time programs. This means that the game should run all the time and not wait for the user to respond. If the user does respond by pressing a key or button, then the game will update based on the user input. A game is also known as a &#8220;state machine&#8221; &#8211; it needs to check if the user pressed a button to show the menu, is the game on level 1 or level 2, is the game paused or running, etc.<\/p>\n<p>A timer is needed, otherwise the game will run either too fast or too slow depending on the computer hardware. The timer will make sure the game will run the same on all systems. The game also needs to allow messages to go back to the operating system (Windows, Mac OS, iOS).<\/p>\n<div id=\"block-bartik-content\" class=\"block block-system block-system-main-block\">\n<div class=\"content\">\n<article class=\"node node--type-page node--view-mode-full clearfix\" data-history-node-id=\"7\">\n<div class=\"node__content clearfix\">\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>The game loop with a timer will act as follows:<\/p>\n<p><span style=\"color: #0000ff;\">1. Show the main menu and get user to start the game<\/span><\/p>\n<p><span style=\"color: #0000ff;\">2. Initialise the game variables, setup memory, menus, etc.<\/span><\/p>\n<p><span style=\"color: #0000ff;\">3. Now start the game and do the following:<\/span><\/p>\n<p><span style=\"color: #ffff00;\">\u00a0\u00a0\u00a0 <span style=\"color: #ff0099;\">3.1 Check if the operating system (Windows, Mac OS, iOS) has any messages for us to process<\/span><\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.2 Get user input (from keyboard, mouse, game controller, touchscreen, etc)<\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.3 Process game logic (maths, physics, update to score, etc go here)<\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.4 Draw the graphics scene of the game to a memory buffer (not video)<\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.5 When this is ready, quickly show it to the screen<\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.6 Wait a little while (fix it at\u00a0a number\u00a0frames per second (FPS) using a timer &#8211; eg 60 FPS)<\/span><\/p>\n<p><span style=\"color: #ff0099;\">\u00a0\u00a0\u00a0 3.7\u00a0 If the game is not finished or user does not quit, go to step 3.1<\/span><\/p>\n<p><span style=\"color: #0000ff;\">4. Once the user quits the game, do a cleanup and free memory allocated<\/span><\/p>\n<p><span style=\"color: #0000ff;\">5.\u00a0 Either go back to step 1 or exit to the operating system (Windows, Mac OS, iOS)<\/span><\/p>\n<p>\u00a0<\/p>\n<\/div>\n<\/div>\n<\/article>\n<\/div>\n<\/div>\n\n\n<p><a href=\"https:\/\/gamedevelopment.tutsplus.com\/articles\/gamedev-glossary-what-is-the-game-loop--gamedev-2469\">More info on game loops is here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Games are real-time programs. This means that the game should run all the time and not wait for the user to respond. If the user does respond by pressing a key or button, then the game will update based on the user input. A game is also known as a &#8220;state machine&#8221; &#8211; it needs &hellip; <a href=\"https:\/\/www.ruzzgames.com\/index.php\/game-loop\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Game Loop<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-69","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/pages\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":10,"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/pages\/69\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/pages\/69\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/www.ruzzgames.com\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}