Memory Tile - SixtyFPS Memory Game Tutorial (C++)

# Memory Tile

With the skeleton in place, let's look at the first element of the game, the memory tile. It will be the visual building block that consists of an underlying filled rectangle background, the icon image. Later we'll add a covering rectangle that acts as a curtain. The background rectangle is declared to be 64 logical pixels wide and tall, and it is filled with a soothing tone of blue. Note how lengths in the `.60` language have a unit, here the `px` suffix. That makes the code easier to read and the compiler can detect when your are accidentally mixing values with different units attached to them.

We copy the following code into the `memory.60` file:

    MemoryTile := Rectangle {
        width: 64px;
        height: 64px;
        background: #3960D5;

        Image {
            source: @image-url("icons/bus.png");
            width: parent.width;
            height: parent.height;
        }
    }

    MainWindow := Window {
        MemoryTile {}
    }

Inside the Rectangle we place an Image element that loads an icon with the @image-url() macro. The path is relative to the folder in which the `memory.60` is located. This icon and others we're going to use later need to be installed first. You can download a Zip archive that we have prepared and extract it with the following two commands:

    curl -O https://sixtyfps.io/blog/memory-game-tutorial/icons.zip
    unzip icons.zip

This should unpack an `icons` directory containing a bunch of icons.

We compile the program with `cmake --build .` and running with the `./memory_game` gives us a window on the screen that shows the icon of a bus on a blue background.