Game Development Reference
In-Depth Information
To reference resources, we use the preceding notation. The @ specifies that we want to reference
a resource defined elsewhere. The following string identifies the type of the resource we want
to reference, which directly maps to one of the folders or files in the res/ directory. The final part
specifies the name of the resource. In the preceding case, this is an image called icon and a
string called app_name . In the case of the image, it's the actual filename we specify, as found in
the res/drawable-xxx/ folders. Note that the image name does not have a suffix like .png or
.jpg . Android will infer the suffix automatically based on what's in the res/drawable-xxx/ folder.
The app_name string is defined in the res/values/strings.xml file, a file where all the strings used
by the application will be stored. The name of the string was defined in the strings.xml file.
Note Resource handling on Android is an extremely flexible, but also complex thing. For this
book, we decided to skip most of resource handling for two reasons: it's utter overkill for game
development, and we want to have full control over our resources. Android has the habit of
modifying resources placed in the res/ folder, especially images (called drawables). That's
something we, as game developers, do not want. The only use we'd suggest for the Android
resource system in game development is internationalizing strings. We won't get into that in this
book; instead, we'll use the more game development-friendly assets/ folder, which leaves our
resources untouched and allows us to specify our own folder hierarchy.
The meaning of the attributes of the <application> element should become a bit clearer now.
The icon attribute specifies the image from the res/drawable/ folder to be used as an icon
for the application. This icon will be displayed in Google Play as well as in the application
launcher on the device. It is also the default icon for all the activities that we define within the
<application> element.
The label attribute specifies the string being displayed for our application in the application
launcher. In the preceding example, this references a string in the res/values/string.xml file,
which is what we specified when we created the Android project in Eclipse. We could also set
this to a raw string, such as My Super Awesome Game . The label is also the default label for all of
the activities that we define in the <application> element. The label will be shown in the title bar
of our application.
We have only discussed a very small subset of the attributes that you can specify for the
<application> element. However, these are sufficient for our game development needs. If you
want to know more, you can find the full documentation on the Android Developers site.
The <application> element contains the definitions of all the application components, including
activities and services, as well as any additional libraries used.
The <activity> Element
Now it's getting interesting. Here's a hypothetical example for our Mr. Nom game:
<activity android:name=". MrNomActivity "
android:label=" Mr. Nom "
 
Search WWH ::




Custom Search