Scala Native SFML

Welcome to the Scala version of the SFML documentation, ported from the official documentation available on the SFML website. Here you will find a detailed view of all the SFML classes and functions. If you are looking for tutorials, you can click on the "Docs" button of the sidebar.

Here is a short example, to show you how simple it is to use SFML:

import sfml.audio.*
import sfml.graphics.*
import sfml.window.*

@main def main =
    /* Create the main window */
    val window = RenderWindow(VideoMode(800, 600), "SFML window")

    /* Load a sprite to display */
    val texture = Texture()
    if !(texture.loadFromFile("cute_image.jpg")) then System.exit(1)

    val sprite = Sprite(texture)

    /* Create a graphical text to display */
    val font = Font()
    if !(font.loadFromFile("arial.ttf")) then System.exit(1)

    val text = Text("Hello SFML", font, 50)

    /* Load a music to play */
    val music = Music()
    if !(music.openFromFile("nice_music.ogg")) then System.exit(1)

    /* Play the music */
    music.play()

    /* Start the game loop */
    while window.isOpen() do
        /* Process events */
        for event <- window.pollEvent() do
            event match
                case Event.Closed() => window.close()
                case _              => ()

        /* Clear screen */
        window.clear()

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

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

        /* Update the window */
        window.display()

    System.exit(0)

Attributes

Members list

Packages

package sfml