View on GitHub

DSFML

Documentation

Here is a short example, to show you how simple it is to use DSFML.

module example;
import dsfml.system;
import dsfml.window;
import dsfml.graphics;
import dsfml.audio;

void main()
{
    // Create the main window
    auto window = new RenderWindow(VideoMode(800, 600), "DSFML window");

    // Load a sprite to display
    auto texture = new Texture();
    if(!texture.loadFromFile("cute_image.jpg"))
        return;

    auto sprite = new Sprite(texture);

    // Create a graphical text to display
    auto font = new Font();
    if(!font.loadFromFile("arial.ttf"))
        return;
    auto text = new Text("Hello DSFML", font, 50);

    // Load a music to play
    auto music = new Music();
    if(!music.openFromFile("nice_music.ogg"))
        return;

    // Play the music
    music.play();

    // Start the game loop
    while(window.isOpen())
    {
        // Process events
        Event event;
        while(window.pollEvent(event))
        {
            // Close window
            if(event.type == Event.EventType.Closed)
                window.close();
        }

        // Clear screen
        window.clear();

        // Draw the sprite
        window.draw(sprite);

        // Draw the string
        window.draw(text);

        // Update the window
        window.display();
    }
}