Indigo

Indigo

  • GitHub
  • Docs
  • Tools

›Getting started

Indigo

  • Indigo's Development Status

Getting started

  • Setup & Configuration
  • Hello, Indigo!
  • Examples
  • Mill & SBT Game Templates

Organising your game

  • Boot & Start Up
  • Game Entry Points
  • Scenes & Scene Management
  • SubSystems

The game loop

  • Events
  • Frame context
  • Outcome Type

Presentation

  • Animation
  • Audio
  • Depth & Layers
  • Effects
  • Lighting
  • Materials
  • Primitives & Building Blocks
  • SceneUpdateFragment Type
  • Text & Fonts
  • UI Components

Working with Time

  • Signals & Signal Functions
  • Time Varying Values

Platform & Publishing

  • Assets & Asset Loading
  • Cross Platform Publishing
  • File Format Importers
  • User Input Handling
  • Loading & Saving Data
  • Logging
  • Networking

Other information

  • Alternatives to Indigo
  • Glossary
  • Key Concepts
  • Model, ViewModel, & View
  • Motivation & Constraints
  • Performance
  • Prior Art
  • Rendering Technology

Setup & Configuration

Updated for release 0.6.0.

Version numbers

Indigo version 0.6.0 is built against the following version numbers:

  • Scala 2.13.4 and 3.0.0-M3
  • Scala.js 1.3.1
  • Mill 0.9.4
  • SBT 1.4.6

Scala 3 Setup Notes

Please note that Scala 3 currently only works with sbt, and the set up will be very similar to the Scala 2 version described below. We hope to add Mill support as soon as possible.

The main difference is that you must remember to include the sbt-dotty plugin:

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.1")

The Cursed Pirate demo has been updated to show a working Indigo + Scala 3 build:

https://github.com/PurpleKingdomGames/indigo-examples/tree/master/demos/pirate

Please note that it still uses Scala 2 syntax, but Scala 3 syntax will work fine.

Building Indigo Games

Indigo games are completely normal Scala.js projects.

Please not that we currently only publish against specific versions of Scala (2.13.4, 3.0.0-M3) and Scala.js (1.3.1).

You can use either Mill (Mill 0.9.4 or above) or SBT (recommend sbt 1.4.6 or greater) to build your games, and for your convenience both Mill and SBT have associated plugins, mill-indigo and sbt-indigo respectively.

The plugins help you bootstrap your game during development, they marshal your assets and serve as a reference implementation for one fairly basic way to embed your game into a web page or electron app.

The plugins let you build a simple web page via the indigoBuild task, or run an Electron app of your game with indigoRun.

Example output from a Mill indigo build of the Snake example game, the SBT version is nearly identical:

> mill snake.buildGame
[46/48] snake.indigoBuild
dirPath: /Users/(...)/indigo/demos/snake/out/snake/indigoBuild/dest
Copying assets...
/Users/(...)/indigo/demos/snake/out/snake/indigoBuild/dest/index.html
[48/48] snake.buildGame

The second to last line is an absolute path to where your game is.

Running your game locally (Electron Application)

You will need to have electron installed globally, install with npm as follows:

npm install -g electron

On Linux, you may find that command is insufficient, you may need something like:

sudo npm install -g electron --unsafe-perm=true --allow-root

Then from your command line:

mill mygame.fastOpt # Compiles and produces the JS file of your game.
mill mygame.indigoRun # First runs indigoBuild, then bundles it into an app and runs it.

Your game should appear on your desktop.

Running your game locally (Web)

If your game is in active development, you might prefer to run it as a website that is slightly quicker to refresh and develop against.

First you need to build your game, as follows:

mill mygame.fastOpt # Compiles and produces the JS file of your game.
mill mygame.indigoBuild # Marshall scripts and assets together and link them to an HTML file.

Most modern browsers do not allow you to run local sites that load in assets and modules just by opening the HTML file in your browser. So if you use the Indigo build tool to produce a bootstrapped game, the quickest way to run it is to use http-server as follows:

  1. Install with npm install -g http-server.
  2. Navigate to the output directory shown after running the indigo plugin.
  3. Run http-server -c-1 - which means "serve this directory as a static site with no caching".
  4. Go to http://127.0.0.1:8080/ (or whatever http-server says in it output) and marvel at your creation..

Scala.js "Fast" vs "Full" Optimisation

The examples below show you how to publish with both "fast" and "full" optimisation of your Scala.js project.

The difference is speed and size. As the name implies, the "fast" version compiles very significantly faster than the "full" version, but even small projects will result in ~5Mb of JavaScript, where the "full" version will be in the region of ~500kb. The "full" version will likely be more performant at run time, for more information please refer to the official Scala.js performance page.

Note that during development the fast version is perfectly acceptable. Your browser will chew through 5-10Mb of JavaScript or more with no problem at all, the performance difference is generally small enough not to be a big deal, and the compilation time reduction is definitely worth it.

Mill Guide

build.sc

Example minimal build.sc file for your game:

import mill._
import mill.scalalib._
import mill.scalajslib._
import mill.scalajslib.api._

import $ivy.`io.indigoengine::mill-indigo:0.6.0`, millindigo._

object mygame extends ScalaJSModule with MillIndigo {
  def scalaVersion   = "2.13.3"
  def scalaJSVersion = "1.3.0"

  val gameAssetsDirectory: os.Path = os.pwd / "assets"
  val showCursor: Boolean          = true
  val title: String                = "My Game"
  val windowStartWidth: Int        = 720 // Width of Electron window, used with `indigoRun`.
  val windowStartHeight: Int       = 480 // Height of Electron window, used with `indigoRun`.

  def ivyDeps = Agg(
    ivy"io.indigoengine::indigo-json-circe::0.6.0",
    ivy"io.indigoengine::indigo::0.6.0"
  )

}

Running via Mill

Run the following:

  1. mill mygame.compile
  2. mill mygame.fastOpt
  3. mill mygame.indigoRun

Building via Mill

Run the following:

  1. mill mygame.compile
  2. mill mygame.fastOpt
  3. mill mygame.indigoBuild

This will output your game and all the correctly referenced assets into out/mygame/indigoBuild/. Note that the module will give you a full path at the end of it's output.

To run as a web site, navigate to the folder, run http-server -c-1, and got to http://127.0.0.1:8080/ in your browser of choice.

Rolling it up into one command in Mill

You can also define the following in your build.sc file inside the mygame object:

  def buildGame() = T.command {
    T {
      compile()
      fastOpt()
      indigoBuild()() // Note the double parenthesis!
    }
  }

  def runGame() = T.command {
    T {
      compile()
      fastOpt()
      indigoRun()() // Note the double parenthesis!
    }
  }

  def buildGameFull() = T.command {
    T {
      compile()
      fullOpt()
      indigoBuildFull()() // Note the double parenthesis!
    }
  }

  def runGameFull() = T.command {
    T {
      compile()
      fullOpt()
      indigoRunFull()() // Note the double parenthesis!
    }
  }

Which allows you to run mill mygame.buildGame and mill mygame.runGame from the command line for the "fast" compile version.

SBT Guide

plugins.sbt

Add the following to your project/plugins.sbt file:

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.1")
addSbtPlugin("io.indigoengine" %% "sbt-indigo" % "0.6.0") // Note the double %%

build.sbt

Example minimal build.sbt file for the root of your project:

lazy val mygame =
  (project in file("."))
    .enablePlugins(ScalaJSPlugin, SbtIndigo) // Enable the Scala.js and Indigo plugins
    .settings( // Standard SBT settings
      name := "mygame",
      version := "0.0.1",
      scalaVersion := "2.13.4",
      organization := "org.mygame"
    )
    .settings( // Indigo specific settings
      showCursor := true,
      title := "My Game",
      gameAssetsDirectory := "assets",
      windowStartWidth := 720, // Width of Electron window, used with `indigoRun`.
      windowStartHeight := 480, // Height of Electron window, used with `indigoRun`.
      libraryDependencies ++= Seq(
        "io.indigoengine" %%% "indigo" % "0.6.0",
        "io.indigoengine" %%% "indigo-json-circe" % "0.6.0",
      )
    )

Running via SBT

Run the following:

sbt compile fastOptJS indigoRun

Building via SBT

Run the following:

sbt compile fastOptJS indigoBuild

This will output your game and all the correctly referenced assets into target/indigoBuild/. Note that the plugin will give you a full path at the end of it's output.

To run as a web site, navigate to the folder, run http-server -c-1, and go to http://127.0.0.1:8080/ in your browser of choice.

Rolling it up into one command in SBT

You can also define the following in your build.sbt file:

addCommandAlias("buildGame", ";compile;fastOptJS;indigoBuild")
addCommandAlias("runGame", ";compile;fastOptJS;indigoRun")
addCommandAlias("buildGameFull", ";compile;fullOptJS;indigoBuildFull")
addCommandAlias("runGameFull", ";compile;fullOptJS;indigoRunFull")

Which give you some convenient shortcuts to speed up development.

← Indigo's Development StatusHello, Indigo! →
  • Version numbers
  • Scala 3 Setup Notes
  • Building Indigo Games
    • Running your game locally (Electron Application)
    • Running your game locally (Web)
  • Scala.js "Fast" vs "Full" Optimisation
  • Mill Guide
    • build.sc
    • Running via Mill
    • Building via Mill
    • Rolling it up into one command in Mill
  • SBT Guide
    • plugins.sbt
    • build.sbt
    • Running via SBT
    • Building via SBT
    • Rolling it up into one command in SBT
Indigo
Getting Started
Setup & Configuration Guide"Hello, Indigo!" TutorialLinks to examplesProject templates
Community
DiscordGitHub DiscussonsTwitter
Sponsor us!
GitHub SponsorsPatreon
Copyright © 2021 Purple Kingdom Games Limited