University of Wales Trinity Saint David
ACCB5017 - Games Architecture and Mechanics

Sourcing Game Assets

Overview

A 2D game needs sprite and sound files from somewhere, and SFML is just as happy loading a texture or a sound buffer regardless of where that file came from. This lab covers finding sprite and sound assets that are explicitly free to use, checking exactly what each one's license allows before it goes into a project, and loading both into a small SFML program to confirm they work. Building on the license-checking habit from the Sourcing Fonts lab, the same principle applies here: an asset downloading without error is not the same as an asset being licensed for the project it ends up in.

Learning Objectives

By the end of this lab you will be able to:

Concept

Every sprite drawn in SFML starts as an ordinary image file on disk, and every sound effect starts as an ordinary audio file. SFML does not check where either one came from, it will load and play a file copied from anywhere just as readily as one bought from a marketplace, so the responsibility for whether that copy is actually allowed sits entirely with the developer, not the engine.

The risk is highest with assets that have no license attached at all, such as an image pulled from a search engine result or a sound clip ripped from a video. Silence on licensing does not mean permission, under copyright law an unlicensed image or recording defaults to all rights reserved, the same as if it had never been marked free. The fix is to source assets only from sites that state a license per item rather than as a vague site-wide claim. OpenGameArt.org and Kenney.nl tag each sprite or tileset with an explicit license, most commonly CC0 (no attribution required, equivalent to public domain) or CC-BY (free to use if the creator is credited). itch.io's free game-assets section hosts packs from individual creators rather than one curated library, so the license is set per creator and stated on that pack's page, it is not a fixed set of tags the way OpenGameArt's are, which makes actually reading that page before downloading even more important. freesound.org tags each sound effect upload with the same Creative Commons family of licenses used for sprites. Reading the license statement on the specific asset, not just the site's homepage, is what makes an asset safe to use. The same rule holds even outside 2D work, marketplaces such as Fab that are built around 3D models and engine content still license each item individually, so the habit this lab builds transfers directly.

Once downloaded, loading is identical regardless of source. sf::Texture::loadFromFile() loads an image file and returns false if it cannot be found or parsed, and an sf::Sprite is then built from that texture with setTexture(). sf::SoundBuffer::loadFromFile() loads an audio file the same way, and an sf::Sound plays it via setBuffer() followed by play().

Packages

PackageDescriptionDocs
OpenGameArt.org Sprite, tileset and audio library. Every submission is tagged with its exact license (CC0, CC-BY, CC-BY-SA and others). opengameart.org
Kenney.nl Sprite and UI asset packs, almost all released under CC0. kenney.nl/assets
itch.io free game assets Individual creators publish sprite and audio packs here. License terms are set by each creator and stated on that page, so check every pack individually rather than assuming one site-wide rule. itch.io/game-assets/free
freesound.org Sound effect and short audio clip library, each upload tagged with its Creative Commons license. freesound.org
Fab Epic's asset marketplace, mostly 3D models, materials and Unreal/Unity content rather than flat 2D sprites. Worth knowing about even for this lab, its per-item license terms follow the same read-before-you-download rule as everything else here. www.fab.com

Tasks

Task 1 - Recognise a license you can rely on

  1. Open a search engine and image-search for a generic game sprite, for example 2d coin sprite png. Look at three or four results without downloading anything.
  2. For each one, try to find a license statement attached to that specific image. In most cases there will be none, only a page it was scraped from.
  3. Now open OpenGameArt.org and view any sprite's page. Note where the license is stated and what it says.

Warning: an image or sound with no license statement is not free to use just because it was easy to find or download. Copyright applies by default whether or not it is mentioned anywhere, so treat an unlicensed file as all rights reserved unless you can point to where it says otherwise. Do not use search-engine results as a source for a project you plan to submit, share or ship.

Success condition: you can state, in one sentence, the difference between what a search engine result and an OpenGameArt.org listing tell you about reuse rights.

Task 2 - Find and download a sprite

  1. Go to OpenGameArt.org, Kenney.nl, or itch.io's free game-assets section (links in the Resources table above) and find a sprite or small tileset suited to a 2D project.
  2. Open the asset's page and read its license statement. On OpenGameArt and Kenney this is a fixed tag (CC0, CC-BY and so on). On itch.io it is written by the individual creator, so read the actual wording rather than assuming it matches a standard license. If it requires attribution, note exactly what credit line it asks for.
  3. Download the asset and extract it if it arrives as a .zip. Locate the actual image file (.png is most common).

Success condition: you have an image file on disk and can state which license it is under and, if CC-BY, what credit line it requires.

Task 3 - Find and download a sound effect

  1. Go to freesound.org and search for a short sound effect, for example coin pickup or jump.
  2. Open a result's page and check its license tag, shown next to the waveform.
  3. Download the file. freesound.org requires a free account to download, creating one is enough, no payment is involved.

Success condition: you have an audio file on disk and can state which license it is under.

Task 4 - Load the sprite and sound in SFML

  1. In your project folder, create assets/textures and assets/sounds folders if they do not already exist, and copy the files from Task 2 and Task 3 into them.
  2. Add the code below to your project, adjusting the two filenames to match what you downloaded.
  3. Build and run.

If either loadFromFile call returns false, check the path is relative to the working directory your project actually runs from (in Visual Studio this is usually the project folder, not the solution folder) rather than assuming the filename alone is wrong.

Success condition: a window opens showing your sprite on screen, and the sound effect plays once when the program starts.

main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Asset Check");

    sf::Texture texture;
    if (!texture.loadFromFile("assets/textures/YourSprite.png"))
    {
        return -1;
    }

    sf::Sprite sprite;
    sprite.setTexture(texture);
    sprite.setPosition(360.f, 260.f);

    sf::SoundBuffer buffer;
    if (!buffer.loadFromFile("assets/sounds/YourSound.wav"))
    {
        return -1;
    }

    sf::Sound sound;
    sound.setBuffer(buffer);
    sound.play();

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color(30, 30, 30));
        window.draw(sprite);
        window.display();
    }

    return 0;
}