Game Development Reference
In-Depth Information
The Android SDK is a set of APIs for developing applications using the Java language. Because the SDK has been
revised and different devices come with different versions of the Android operating system, there are different API
levels. At the time of this writing, the most recent is API Level 19. It corresponds to version 4.4 of the OS, otherwise
known as the Kit Kat release 3 . However, you can use a lower API Level to be able to target older devices. The user
interface, which comprises the majority of code in your game prototyping tool, will be written in Java.
As a way to allow native development on the Android platform and for developers to take advantage of existing
C/C++ code libraries, the NDK was released. Like the SDK, it has been through several revisions, and the latest one at
the time of writing is Revision 9d 4 . The core of your tool, the scripting system, will be written in C/C++ and compiled
into a shared library.
To make development easier, an integrated development environment (IDE) will be used for writing code and
building the project. Developers nowadays have their choice of software, and the reader is welcome to use their
preferred IDE. However, it is worth mentioning that Eclipse makes it easy to write Android applications. The ADT
plug-in adds project templates for Android development, tools to create user interface layouts, Android debugging
capabilities, and more. 5
Cygwin is an optional tool that provides a Unix-like environment on the Windows platform 6 . You will use it for
building native code into libraries usable by Android applications. The Android NDK comes with the ndk-build shell
script that must run in a Unix-like environment. The reason it's optional is that as of NDK Revision 7, there is a new
Windows-compatible build script. The ndk-build.cmd script allows developers to build native code libraries on a
Windows system without Cygwin. However, the documentation lists this script as an experimental feature of NDK
Revision 7, so it may have issues.
The scripting library used in this article is AngelScript. This is an open source project developed by Andreas Jönsson
that includes contributions by many other developers. You will use it to build the core of your game prototyping tool,
which is a script engine. It will be responsible for initializing and updating a scene full of game objects.
Code Structure
An Android application is generally written in Java and is made up of one or more Activity classes. Each activity can
set one or more View objects as a user interface. One activity is enough for the prototyping tool, which will implement
three different views: a scene editing canvas, a script text editor, and a scene-playing screen. A list of game objects will
be kept when editing a scene and when playing it, so you'll write a couple of classes that represent game objects. To
run scripts while playing a scene, the tool will interface with a basic scripting engine written in C/C++. Java code will
take care of calling native code and getting what it needs from the script engine; this will happen via the Java Native
Interface. Some advantages of JNI are reusing an existing code library without converting it to another language,
better performance by running some processes in a native environment instead of a virtual machine, and ease of
porting to other platforms that support native code. On the C/C++ side there will be a main source file and a pair of
.h /. cpp files for a script engine class. Table 12-2 lists all source files and their purpose.
3 Google Inc. “Codenames, Tags, and Build Numbers.” Accessed April 9, 2014. http://source.android.com/source/
build-numbers.html .
4 Google Inc. “Android NDK.” Accessed November 12, 2011. http://developer.android.com/tools/sdk/ndk/index.html .
5 Google Inc. “ADT Plug-in.” Accessed November 12, 2011. http://developer.android.com/tools/sdk/eclipse-adt.html .
6 Red Hat. “Cygwin.” Accessed November 12, 2011. www.cygwin.com/ .
 
Search WWH ::




Custom Search