IMGD 3000 Stand-alone Game for Mac

Packaging a Dragonfly Game


Top   |   Layout   |   Package   |   Test   |   Player

This page describes how to make a stand-alone version of your Dragonfly game for Mac, as needed for the Stand-alone Game part of the Project 3 promotional materials. The result is a zipped folder that, when extracted, lets the player run your compiled game from the command line (Terminal) - no source code, engine or SFML install needed.

Note, this is not a Mac .app bundle. It is just a plain folder with your game in it.

In the examples below, the game is called my-game. Replace that with the name of your game.

For other platforms, see Windows or Linux.


Top   |   Layout   |   Package   |   Test   |   Player

Folder Layout

When done, your stand-alone game folder should look like:

my-game/
  my-game              <- release binary
  run.sh               <- launcher script
  df-font.ttf
  sprites/
  sounds/
  lib/                 <- SFML .dylib files

Top   |   Layout   |   Package   |   Test   |   Player

Package

  1. Build a Release version of your game using the release version of the SFML libraries and a release version of Dragonfly, as appropriate.

  2. Make a new, empty folder, with a lib/ folder inside it.

    mkdir -p my-game/lib
  3. Copy in the executable, the Dragonfly font file and the needed sprites and sounds.

    cp path/to/build/my-game my-game/
    cp -R df-font.ttf sprites sounds my-game/
  4. Copy the SFML libraries (from SFML/lib) into lib/. Use otool -L my-game/my-game to see which ones your game needs. Only copy the libsfml-*.3.1.dylib names it lists, and use cp -L so you copy the actual files and not symlinks.

    for l in graphics window system audio; do
      cp -L ~/src/SFML/lib/libsfml-$l.3.1.dylib my-game/lib/
    done
  5. Add a launcher script, my-game/run.sh. Dragonfly loads the sprites, sounds and font from the current directory (and writes dragonfly.log there), so the script changes to the game folder first. That way, the game runs no matter where it is called from.

    #!/bin/sh
    cd "$(dirname "$0")" && exec ./my-game "$@"
  6. Point the game at the bundled libraries. Use install_name_tool to add an @rpath of @executable_path/lib. Also remove the @rpath to your own SFML build, so the game can’t pick up your local copy by mistake. (Use otool -l my-game/my-game | grep -A2 LC_RPATH to see the current one.)

    install_name_tool -delete_rpath ~/src/SFML/lib my-game/my-game
    install_name_tool -add_rpath "@executable_path/lib" my-game/my-game
  7. Re-sign the game and libraries. install_name_tool breaks the code signature, and Apple Silicon Macs won’t run unsigned code (the game just gets Killed: 9). An ad-hoc signature is enough:

    codesign --force -s - my-game/my-game my-game/lib/*.dylib
  8. Make sure the game and script can be run, then zip up the folder (-y keeps any symlinks as symlinks).

    chmod +x my-game/my-game my-game/run.sh
    zip -ry my-game.zip my-game

Tip! The game only runs on Macs with the same kind of processor it was built on. Use file my-game/my-game to check - arm64 is Apple Silicon and x86_64 is Intel.


Top   |   Layout   |   Package   |   Test   |   Player

Test

Make sure to test the installation by extracting in a different location (ideally, on another computer) and verifying it can run!

mkdir /tmp/test && cd /tmp/test && unzip ~/path/to/my-game.zip
./my-game/run.sh

Top   |   Layout   |   Package   |   Test   |   Player

Instructions for the Player

Include these steps (e.g., in a README) with your zipped game.

  1. Download and extract my-game.zip. Double-click it in Finder, or run unzip my-game.zip.

  2. Since the game is not signed by an Apple developer, macOS blocks it after a browser download. Remove the block from Terminal with:

    xattr -dr com.apple.quarantine path/to/my-game
  3. Run the game:

    path/to/my-game/run.sh

Top   |   Layout   |   Package   |   Test   |   Player

Return to Project 3