{"id":1286,"date":"2012-04-08T18:08:54","date_gmt":"2012-04-08T18:08:54","guid":{"rendered":"http:\/\/www.drmop.com\/?p=1286"},"modified":"2012-04-08T18:08:54","modified_gmt":"2012-04-08T18:08:54","slug":"iwgame-engine-tutorial-the-game","status":"publish","type":"post","link":"http:\/\/www.drmop.com\/index.php\/2012\/04\/08\/iwgame-engine-tutorial-the-game\/","title":{"rendered":"IwGame Engine Tutorial &#8211; The Game"},"content":{"rendered":"<h1>CIwGame Object \u2013 The Eye in the Sky<\/h1>\n<h2>Introduction<\/h2>\n<p>CIwGame is basically the kind of eye-in-the-sky controller of the game engine and can be thought of as the main loop of the game engine. CIwGame takes care of many things including:<\/p>\n<ul>\n<li>Initialisation, processing and clean-up of many systems including graphics, input, resource manager and audio etc..<\/li>\n<li>Managing and updating scenes<\/li>\n<li>Sorting scenes by layer order<\/li>\n<li>Notifying the user of scene change events<\/li>\n<li>Rendering scenes<\/li>\n<li>Tracking frame speed<\/li>\n<li>Processing events such as tapped, touch begin \/ end<\/li>\n<\/ul>\n<p>You never actually create an instance of CIwGame, instead you derive you own version of the class from CIwGame like this:<\/p>\n<pre>#define\tGAME\tGame::getInstance()\r\n\r\nclass Game : public CIwGame\r\n{\r\n\tCDEFINE_SINGLETON(Game)\r\npublic:\r\nprotected:\r\n\t<span style=\"color: #008000;\">\/\/\/\/ Properties<\/span>\r\npublic:\r\n\t<span style=\"color: #008000;\">\/\/\/\/ Properties end<\/span>\r\nprotected:\r\npublic:\r\n\tvoid\t\t\tInit(bool enable_http);\r\n\tvoid\t\t\tRelease();\r\n\tbool\t\t\tUpdate();\r\n\tvoid\t\t\tDraw();\r\n\tvoid\t\t\tPostDraw();\r\n\tvoid\t\t\tSave();\r\n\tvoid\t\t\tLoad();\r\n};<\/pre>\n<p>You then implement Init(), Release(), Update() and Draw() methods to provide your own initialisation, clean-up, per frame update and per frame rendering code. You can also override PostDraw() to apply post rendering.<\/p>\n<p>Note that the games Init() method takes a parameter called enable_http. If you plan on using anything relating to the HTTP manager, such as ads, web file \/ image access then you will need to pass true to the game object during initialisation.<\/p>\n<h2>Implementing our own CIwGame<\/h2>\n<p>Lets now take a quick look at a bare bones implementation of the above methods:<\/p>\n<pre>CDECLARE_SINGLETON(Game)\r\n\r\nvoid Game::Init(bool enable_http)\r\n{\r\n\tCIwGame::Init(enable_http);\r\n\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own initialisation here<\/span>\r\n}\r\n\r\nvoid Game::Release()\r\n{\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own cleanup here<\/span>\r\n\r\n\tCIwGame::Release();\r\n}\r\n\r\nbool Game::Update()\r\n{\r\n\tif (!CIwGame::Update())\r\n\t\treturn false;\r\n\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own custom game update functionality here<\/span>\r\n\r\n\treturn true;\r\n}\r\n\r\nvoid Game::Draw()\r\n{\r\n\tCIwGame::Draw();\r\n\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own custom game rendering functionality here<\/span>\r\n}\r\n\r\nvoid Game::Save()\r\n{\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own game save functionality<\/span>\r\n}\r\n\r\nvoid Game::Load()\r\n{\r\n\t<span style=\"color: #008000;\">\/\/ TODO: Insert your own game load functionality<\/span>\r\n}<\/pre>\n<p>Note that if you utilise IwGames systems then it is very unlikely that you will need to add additional rendering code to Game::Draw().<\/p>\n<p>At its heart, CIwGame contains a collection of game scenes (CIwGameScene&#8217;s) that in turn drive actors and cameras to provide your games functionality (more on these classes later).<\/p>\n<p>CIwGame enables you to add, remove and search for scenes within the game as well as set the currently active scene using the following methods:<\/p>\n<pre>void\t\taddScene(CIwGameScene *scene, bool bring_to_front = true);\r\nvoid\t\tremoveScene(CIwGameScene* scene);\r\nvoid\t\tremoveScene(unsigned int name_hash);\r\nCIwGameScene*\tfindScene(unsigned int name_hash);\r\nCIwGameScene*\tfindScene(const char* name);\r\nCIwGameScene*\tfindScene(int type);\r\nCIwGameScene*\tgetScene(int index);\r\nvoid\t\tclearScenes();\r\nvoid\t\tchangeScene(CIwGameScene *new_scene);\r\nbool\t\tchangeScene(unsigned int name_hash);\r\nCIwGameScene*\tgetCurrentScene();\r\nvoid\t\tBringSceneToFront(CIwGameScene* scene);<\/pre>\n<p>Note that all visible scenes will be rendered every game frame and usually only the current scene will be updated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CIwGame Object \u2013 The Eye in the Sky Introduction CIwGame is basically the kind of eye-in-the-sky controller of the game engine and can be thought of as the main loop of the game engine. CIwGame takes care of many things including: Initialisation, processing and clean-up of many systems including graphics, input, resource manager and audio [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[181,1],"tags":[364],"class_list":["post-1286","post","type-post","status-publish","format-standard","hentry","category-iwgame-engine","category-uncategorized","tag-iwgame-engine-tutorial"],"_links":{"self":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":4,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1291,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1291"}],"wp:attachment":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}