Features and API

The gamnit framework is split in two main API, each with their specialty but both are fully compatible.

Easy 2D API

Import gamnit::flat to create a 2D game or app. It provides a simple API centered on Sprite and Texture. Setup the game in create_scene and update the game logic in update(dt).

Load a texture and create a sprite

import gamnit::flat

redef class App
  # Load a texture from the assets folder
  var texture = new Texture("fighter.png")

  redef fun create_scene do
    # Add a sprite to the visible world
    var sprite = new Sprite(texture, new Point3d[Float])
    sprite.scale = 2.0
    sprites.add sprite
  end

  redef fun update(dt) do
    # Rotate all sprites at 180° per second
    for sprite in sprites do
      sprite.rotation += dt * pi
    end
  end
end

View doc »

Powerful 3D API

Go beyond the flat API by importing gamnit::depth. It provides 3D Actor with their shape set by a Mesh and their color by a Material. You can create Material subclasses to define your own shaders.

Load a model and create a 3D actor

  # Load a 3D model from the assets folder
  var tree = new Model("tree.obj")

  # Or create a simple blue cube
  var cube = new LeafModel(new Cube, new Material)

  # Create a 3D actor
  var actor = new Actor(tree, new Point3d[Float])
  app.actors.add actor

View doc »

Other useful services

  • Use other assets with Sound, Music and BMFont.
  • Display a simple touch UI with gamnit::virtual_gamepad.
  • Communicate easily over the network with gamnit::network.
  • Add haptic feedback with android::vibration.
  • Save game state, user preferences and send data on the network with serialization, json and msgpack.

Featured projects

Already a few games show off what gamnit can do!

Asteronits

Simple version of a classic, with a clean separation of the game and display logic using Nit's class refinement.

View source

Summit Way

A beautiful and peaceful mobile puzzle game where you place bridges to form a loop between all hills.

Get it on Google Play

Jump 'n' Gun

Rocket jump from tower to tower in this first person shooter, with multiplayer support and custom OpenGL ES calls.

View source

Model Viewer

Display 3D models from local assets or from a path passed as command line argument, useful to debug model loading.

View source

Devil's Avocados

Puzzle platformer with four levels, a nice story, nacho chip enemies and avocado throwing physics.

View source

Action Nitro

Ridiculous platformer action shooter game with some 3D elements and moving platforms.

View source

Getting started

We document here how to target GNU/Linux, Android and iOS. The macOS desktop is not supported as a target at this time.

Windows desktop is supported using msys2, follow the Windows guide, then install required packages.

Setup a GNU/Linux system

To compile Nit tools and gamnit apps, install all the required packages with the following command (for Debian and Ubuntu):

sudo apt-get install build-essential ccache libgc-dev \
  graphviz libunwind-dev pkg-config libgles2-mesa-dev \
  libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev inkscape

Clone the Nit repo, compile the Nit tools and configure your environment:

git clone https://github.com/nitlang/nit.git
cd nit
make
. misc/nit_env.sh install

Test your installation with Asteronits for the desktop:

cd contrib/asteronits
make
bin/asteronits

To compile for Android, you will need to install the SDK and NDK, set the ANDROID_HOME environment variable and install OpenJDK 8. See the detailed host system setup guide for Android targets.

Setup a macOS host to target iOS

Make sure to install Xcode and launch it once to accept the license agreement. Then install brew and use it to install the required packages with the following command:

brew install ccache bdw-gc libunwind-headers pkgconfig \
  graphviz ios-sim

Clone the Nit repo, compile the Nit tools and configure your environment:

git clone https://github.com/nitlang/nit.git
cd nit
make
. misc/nit_env.sh install

Test your installation by compiling Asteronits for iOS:

cd contrib/asteronits
make ios
ios-sim launch --devicetypeid "iPhone-8, 11.2" \
  bin/asteronits.app

Create a new project

To create your own project, copy and rename the template project:

cp -r lib/gamnit/examples/template my_game
cd my_game
mv src/template.nit src/my_game.nit
find -type f -exec sed -i -e s/template/my_game/g {} \;

On GNU/Linux, compile and run for the desktop:

nitc src/my_game.nit -m linux
./my_game

Compile for Android and install on a device:

nitc src/my_game.nit -m android -o my_game.apk
adb install my_game.apk

Develop your project

Compile for iOS from macOS and launch in the simulator:

nitc src/my_game.nit -m ios -o my_game.app --compile-dir out
ios-sim launch --devicetypeid "iPhone-8, 11.2" my_game.app

To run on a physical device, compile the generated C code with Xcode:

open -a xcode out/ios/my_game_m_ios.xcodeproj

Modify this project and build upon it!

  • Add modules and separate concerns using class refinement.
  • Store the root game logic object in the class App.
  • Update your game logic in the method update.
  • Extend the project using the depth API.
  • Update package.ini before publishing.

Philosophy

The development of gamnit is guided by a philosophy placing coding and efficiency first.

Code first for fast prototyping

Start coding using the flat 2D API to create a prototype and gradually introduce advanced features with the depth 3D API. Additional modules offer solutions to common needs.

Powerful and refinable

The underlying OpenGL ES 2.0 can be accessed by writing shaders in custom materials, or by refining drawing methods and adding custom Nit or C code.

Portable and mobile oriented

Built on OpenGL ES 2.0, apps are portable to GNU/Linux, Android and Windows. Beyond the prototype, apps can be adapted to each platform using their native languages nested within Nit modules.

Free as in freedom

The gamnit project and Nit language are free software published under Apache 2.0. We encourage you to read the source code, modify it and share your improvements.