{"author_name":"spacechase0","cat":"LD #23","comments":[],"epoch":1334608260,"likes":0,"metadata":{"p_key":"59436","p_author":"spacechase0","p_authorkey":"10574","p_urlkey":"95187","p_title":"Game Base","p_cat":"LD #23","p_event":"LD23","p_time":"1334608260","p_likes":"0","p_comments":"0","p_status":"UPD5","us_key":"10574","us_name":"spacechase0","us_username":"spacechase0","event_start":"1334880000","event_key":"10","event_name":"LD23"},"text":"<p>Not really a whole lot, but still: <a href=\"https:\/\/github.com\/spacechase0\/Game-Base\">Click<\/a>. It&#8217;s for C++\/SFML2. <strong>Make sure C++0x\/C++11 is enabled.<\/strong><\/p>\n <p><span id=\"more-112936\"><\/span><\/p>\n <p>You&#8217;d put all your game code in <tt>scenes\/GameScene<\/tt>, with your variables as member variables and then your normal loop stuff throughout the five functions: <tt>initialize( SceneChangeEvent&amp; )<\/tt>, <tt>terminate()<\/tt>, <tt>update()<\/tt>, <tt>update( const sf::Event&amp; )<\/tt>, and <tt>render( sf::RenderWindow&amp; )<\/tt>.<\/p>\n <ul>\n <li><tt>initialize( SceneChangeEvent&amp; )<\/tt> is called the frame after a scene is activated. More on <tt>SceneChangeEvent<\/tt> later.<\/li>\n <li><tt>terminate()<\/tt> is called when the scene is deactivated. This, like <tt>initialize( SceneChangeEvent&amp; )<\/tt>, is called at the beginning of the frame <em>after<\/em> a scene change is requested. This is to avoid various bugs I&#8217;ve encountered in the past (which I don&#8217;t remember). \ud83d\ude1b<\/li>\n <li><tt>update()<\/tt> is called X times a second, where X is equal to <tt>Game::UPDATE_RATE<\/tt> (default 50). If it somehow gets behind, it will try to catch up.<\/li>\n <li><tt>update( const sf::Event&amp; event )<\/tt> is only called when <tt>update()<\/tt> is called, <strong>but<\/strong> is only called if we get an event from SFML. So, you could get 5 of these in one frame, or get none for several.<\/li>\n <li><tt>render( sf::RenderWindow&amp; )<\/tt> is called Y times a second, where Y is equal to <tt>Game::RENDER_RATE<\/tt> (default 50). This is just a call to <tt>sf::RenderWindow::setFramerateLimit( unsigned int )<\/tt>. If this gets behind, oh well. \ud83d\ude1b<\/li>\n <\/ul>\n <p><tt>SceneChangeEvent<\/tt> is my way of passing information to a different scene when you change scenes without having to do something like <tt>std::dynamic_pointer_cast( game.getScene( \"Options\" ) )-&gt;setSceneChangeData( someParameterA, someParameterB, ... )<\/tt>. Basically, if you need to pass some data, you would add an entry in <tt>SceneChangeEvent::Reason<\/tt> (like <tt>GameSaveSelected<\/tt>), and then add a struct to the union, <a href=\"http:\/\/pastebin.com\/xne3yQ5F\">like this<\/a>. Then, just create an instance of <tt>SceneChangeEvent<\/tt>, set the data, and change scenes. <img src=\"http:\/\/ludumdare.com\/compo\/wp-includes\/images\/smilies\/simple-smile.png\" alt=\":)\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/p>\n <p><tt>ResourceManager<\/tt> is just a convenient way of getting resources without having to declare them, loading them, checking for errors, etc. all the time. For instance, to get an <tt>sf::Texture<\/tt>, you would run <tt>ResourceManager::getTexture( \"image.png\" )<\/tt>, and it will return the texture, or an empty pointer if loading failed. If loading fails, it <em>also<\/em> prints out to <tt>std::cout<\/tt>.<\/p>\n <p>Now, you can either stuff every bit of code into the default <tt>scenes\/GameScene<\/tt>, or you can be nice and separate your main menu, splash screens, etc. into their own <tt>Scene<\/tt>s. \ud83d\ude1b<\/p>","time":"April 16th, 2012 3:31 pm","title":"Game Base"}