Game Development Reference
In-Depth Information
Just remember to always put all your assets into the
assets
folder under
the
demo-android
project. The reason behind this is that the Android
build process requires direct access to the application's
assets
folder.
During its build process, a Java source file,
R.java
, will be automatically
generated under the
gen
folder. It contains special information for
Android about the available assets. It will be the usual way to access
assets through the Java code if you were explicitly writing an Android
application. However, in LibGDX, you will want to stay independent of
the platform as much as possible and access any resource such as assets
only through the methods provided by LibGDX. You will learn more
about accessing resources in the last section of this chapter.
You might wonder how other platform-specific projects will be able to access the
very same assets without having to maintain several copies per project. Needless to
say this would require you to keep all copies manually synchronized each time the
assets change.
Luckily, this problem has already been taken care of by the generator. The
demo-
desktop
project uses a linked resource—a feature by Eclipse—to add existing files
or folders to other places in a workspace. You can check this out by right-clicking on
the
demo-desktop
project, navigating to
Properties
|
Resource
|
Linked Resources
,
and then clicking on the
Linked Resources
tab.
The
demo-html
project requires another approach as
Google Web Toolkit
(
GWT
)
has a different build process compared to other projects. There is a special file called
GwtDefinition.gwt.xml
that allows you to set the asset path by setting the
gdx.
assetpath
configuration property to the
assets
folder of the Android project. Notice
that it is good practice to use relative paths such as
../ android/assets
so that the
reference does not get broken if the workspace is moved from its original location.
Take this advice as a precaution to protect you and your fellow developers from
wasting precious time on something that can be easily avoided by using the right
setup, right from the beginning.
The following is the code listing for
GwtDefinition.gwt.xml
from
demo-html
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit
trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/
distro-source/core/src/gwt-module.dtd">
<module>