Wednesday, January 19, 2011

The Ultimate Guide for Android Developers The Latest Releases

Welcome to the world of Android Games! The goal of this book is to help you build the best games for the
platform. As you work your way through the chapters, you will learn how to create two kinds of games:
pure Java, and perhaps most interestingly, hybrid games that combine the elegant design of Java with the raw power of C for maximum performance. The ability to combine both Java and C in this way is what makes the games in this book unique, as Google does not support this kind of development. But you may ask, “Why even bother with hybrid games?” After all, Java provides all the APIs you need to build any kind of game. This is certainly true.

However, there are thousands of games out there written in C that can be brought to Android by compiling the C core and wrapping a Java graphical user interface (GUI) using the Java Native Interface (JNI). In this book, you’ll learn how to bring to the platform two of the great 3D shooter games for the PC: Wolfenstein 3D and Doom. The bottom line? My goal is to bring to you the latest documented and undocumented secrets to
building games for Android. Furthermore, if your plan is to port a PC game, this book will provide you with invaluable expertise to do so. But before we get started, there are some things you need to know to get the most from this book.

A Solid Foundation of Android
This book assumes that you already know the basics of Android development. For example, you need to
know what activities, views, and layouts are. Consider the following fragment. If you understand what it
does just by looking at it, then you are in good shape.
public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

This fragment defines the main activity or class that controls the life cycle of the application. The onCreate method will be called once when the application starts, and its job is to set the content layout or GUI for the application. You should also have a basic understanding of how GUIs are created using XML. Look at the next fragment. Can you tell what it does?


xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/doom"
android:focusableInTouchMode="true" android:focusable="true"/>

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/img1" />


This code defines a relative layout. In a relative layout, widgets are placed relative to each other (sometimes overlapping). In this case, there is an image view that fills the entire screen. This image will display as the background the file called doom.png stored in the res/drawable folder of the project, and receive key and touch events. In the lower left of the screen, overlapping the image view, an image button with the ID btn_upleft will be displayed.

There are a lot of concepts related to Android development, and it is impossible to remember every detail
about activities, views, and layouts. A handy place to access this information quickly is the Android tutorial:
http://developer.android.com/

The ultimate guide for Android developers the latest releases, downloads, SDK Quick Start, version
notes, native development tools, and previous releases—can be found here:
http://developer.android.com/sdk/1.6_r1/index.html

Throughout this book (especially in the chapters dealing with native code), I make extensive use of the Android Software Development Kit (SDK) command tools (for system administrator tasks). Thus,
you should have a clear understanding of these tools, especially the Android Debug Bridge (adb). You
should know how to do the following:
• Create an Android Virtual Device (AVD). An AVD encapsulates settings for a specific device configuration, such as firmware version and SD card path. Creating an AVD is really simple and can be done from the integrated development environment (IDE) by using the AVD Manager (accessed by clicking the black phone icon in the toolbar).

• Create an SD card file. Some of the games in later chapters have big files (5MB or more). To save space, the code stores all game files in the device SD card, and you should know how to create one. For example, to create a 100MB SD card file called sdcard.iso in your home directory, use this command:
$ mksdcard 100M $HOME/sdcard.iso

• Connect to the emulator. You need to do this for miscellaneous system administration, such as library extraction. To open a shell to the device, use this command: $ adb shell

• Upload and pull files from the emulator. These tasks are helpful for storing and extracting game files to and from the device. Use these commands:
$ adb push
$ adb pull

0 comments:

Post a Comment