This post has been migrated from an old server & blog system. Some things may look strange, such as formatting. Some links and images may be broken. I will try getting around to fixing it ASAP.
Now that I have SFML, GCC and Code::Blocks playing nicely on my computer, I spent a little bit of time seeing what I can do with SFML. I wish that SFML had a set of tutorials similar to
Lazy Foo's SDL tutorials but the
tutorials on SFML's site are not too bad. After following the tutorials, I managed the following:
[caption id="attachment_359" align="alignnone" width="300" caption="A game involving a cat floating in nothingness, questioning his own existence."]
[/caption]
Sure, it isn't a lot. Actually, it's just a small sprite of a cat being loaded and drawn onto an 800x600-sized window. That's it. Here is the source:
[cpp]#include <SFML/Graphics.hpp>
int main(int argc, char** argv)
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Cat: The Game"); // the window
sf::Image image;
if(!image.LoadFromFile("small_cat_0.jpg"))
{
App.Close();
}
sf::Sprite sprite;
sprite.SetImage(image);
sprite.SetX(100);
sprite.SetY(200);
while(App.IsOpened())
{
sf::Event event; // event catcher
if(App.GetEvent(event)) // if there is an event in the stack returns true, otherwise returns false
{
if(event.Type == sf::Event::Closed) // if user closed the box by clicking the close button
App.Close();
}
App.Clear();
App.Draw(sprite);
App.Display();
}
return 0;
}[/cpp]
This is the result of me playing around with SFML for around 20 minutes. First, an instance of a RenderWindow (window capable of... rendering!) object is created, being passed window size, bpp, and window title. Then an image object is created, with the cat loaded into that image from a local file. If the image load fails, the program exits. Otherwise, a sprite object is created and then assigned the cat image. I have not really played around with the sprite class that much yet but the
documentation for the class shouldn't make it difficult. I give x and y coordinates for the image, and then enter the main loop. An event handler is created, and is then checked to see if the user exits the application via the close button or not. If not, it just clears the screen and re-draws the application and cat image.
It isn't much, but it is a start! I am trying to think of ways to encapsulate SFML into a basic game engine. Tomorrow, I should have something that could at least be called 'interactive' if not a 'game'.