Home | Rules and Guide | Sign In/Create Account | Write a Post | Reddit | #ludumdare on irc.afternet.org (Info)

Thanks for making Ludum Dare 26 AWESOME! See you in August!

Ludum Dare 26 — April 26-29th, 2013
[ Results: Top 100 Compo, Jam | Top 25 Categories | View My Entry ]
[ View All 2346 Games (Compo Only, Jam Only) | Warmup ]

[ 10 Sec Video Compilation (x3) | 260 Game Video Compilation | IndieCade Deal | Ludum Deals (Unity Deal Ends Soon!) ]


Game Base

Posted by
April 16th, 2012 3:31 pm

Not really a whole lot, but still: Click. It’s for C++/SFML2. Make sure C++0x/C++11 is enabled.

You’d put all your game code in scenes/GameScene, with your variables as member variables and then your normal loop stuff throughout the five functions: initialize( SceneChangeEvent& ), terminate(), update(), update( const sf::Event& ), and render( sf::RenderWindow& ).

  • initialize( SceneChangeEvent& ) is called the frame after a scene is activated. More on SceneChangeEvent later.
  • terminate() is called when the scene is deactivated. This, like initialize( SceneChangeEvent& ), is called at the beginning of the frame after a scene change is requested. This is to avoid various bugs I’ve encountered in the past (which I don’t remember). :P
  • update() is called X times a second, where X is equal to Game::UPDATE_RATE (default 50). If it somehow gets behind, it will try to catch up.
  • update( const sf::Event& event ) is only called when update() is called, but 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.
  • render( sf::RenderWindow& ) is called Y times a second, where Y is equal to Game::RENDER_RATE (default 50). This is just a call to sf::RenderWindow::setFramerateLimit( unsigned int ). If this gets behind, oh well. :P

SceneChangeEvent is my way of passing information to a different scene when you change scenes without having to do something like std::dynamic_pointer_cast( game.getScene( "Options" ) )->setSceneChangeData( someParameterA, someParameterB, ... ). Basically, if you need to pass some data, you would add an entry in SceneChangeEvent::Reason (like GameSaveSelected), and then add a struct to the union, like this. Then, just create an instance of SceneChangeEvent, set the data, and change scenes. :)

ResourceManager 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 sf::Texture, you would run ResourceManager::getTexture( "image.png" ), and it will return the texture, or an empty pointer if loading failed. If loading fails, it also prints out to std::cout.

Now, you can either stuff every bit of code into the default scenes/GameScene, or you can be nice and separate your main menu, splash screens, etc. into their own Scenes. :P

Leave a Reply

You must be logged in to post a comment.


All posts, images, and comments are owned by their creators.

[cache: storing page]