Gameduino 2 code

To install the Gameduino 2 libary:

  1. download the Gameduino2.zip library
  2. install it in the Arduino IDE. Instructions for doing this are at http://arduino.cc/en/Guide/Libraries
  3. if you do not have a microSD card, download Gameduino2sd.zip and copy it contents onto a formatted microSD card
  4. restart the Arduino IDE, and load one of the sketches, for example File Sketchbook libraries Gameduino2 1.Basics helloworld
/sphinx/_images/menu.png

The asset converter

The asset converter is a program that prepares media on your PC for use with the Gameduino 2. You can use the asset converter to:

  • convert sprite graphics for the Gameduino2
  • convert audio samples
  • convert TrueType (TTF) fonts

After installation, you can run the asset converter by typing:

gd2asset --help

into a command shell. You should see something like:

usage: gd2asset <options> <assets>

  -o   output header file
  -f   output asset file (default is header file)

If no output header file is given, then "default_assets.h" is used

Each asset is a filename, optionally followed by some var=val
assignments. For example:
  pic1.png                 image, format ARGB4
  pic2.jpg,format=L8       image, format L8
  serif.ttf,size=16        font, 16 pixels high

The assets are compiled into flash, or if the "-f" option is given
into a file. In this case the file should be copied to the
microSD card.
In either case, calling LOAD_ASSETS() from the program loads all
assets.

There are two ways of storing assets. The first is to use an array in Arduino flash memory. This works well for small sized assets, up to around 20K. The second way is to load the assets from SDcard memory.

If you run it like this:

gd2asset -o myassets.h pic1.png pic2.png pic3.png

then it creates a file myassets.h. Add it to your Arduino sketch, and in your sketch do:

#include "myassets.h"

and after GD.begin(), do:

LOAD_ASSETS();

and you can use the assets pic1, pic2, pic3, for example:

GD.Begin(BITMAPS);
GD.Vertex2ii(10, 100, 0); // pic1
GD.Vertex2ii(10, 200, 1); // pic2
GD.Vertex2ii(10, 300, 2); // pic3

If you run gd2asset like this:

gd2asset -f myassets.gd2 -o myassets.h pic1.png pic2.png pic3.png

then it creates two files:

  • myassets.gd2 - copy this onto your microSD
  • myassets.h - include this from your program

Copy myassets.gd2 to the SDcard, and the sketch can use the assets as above. The only difference is that the data is stored on the SDcard instead of taking up flash memory.

Installation on Debian/Ubuntu

The Gameduino 2 asset converter is available at https://pypi.python.org/pypi/gameduino2.

If your system does not already have easy_install and PIL:

sudo apt-get install python-setuptools python-imaging

then you can install the asset converter with:

sudo easy_install -U gameduino2

and run it by typing:

gd2asset

Installation on Windows

For Windows, your need to install several packages:

  1. Python27, http://www.python.org/getit/windows/
  2. easy_install from https://pypi.python.org/pypi/setuptools#windows-powershell-3-or-later
  3. The Python Imaging Library, http://www.pythonware.com/products/pil/. Choose the version for Python 27.

After this you can open a command windows and type:

\Python27\Scripts\easy_install -U gameduino2

You should see something like this:

/sphinx/_images/asset-win-2.png

This installs the Python package gameduino2 and the command-line utility gd2asset.

After setup you can run it with a command-line like this:

\Python27\python \Python27\Scripts\gd2asset

For general help about setting up Python tools on Windows, see http://docs.python.org/2/faq/windows