Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 195 | chris | 1 | -- libgdx -- |
| 2 | Hi there, you seem to have downloaded libgdx so let me explain to you how to setup your projects. |
||
| 3 | The following assumes that you are going the proper libgdx way, that is developing your app on the |
||
| 4 | Desktop and then painlessly droping it on your Android device without any further code modifications. |
||
| 5 | We go through this step by step. |
||
| 6 | |||
| 7 | 1) Setting up the desktop Java project |
||
| 8 | Open Eclipse and create a new Java project called gdx-helloworld. Within the project create a new |
||
| 9 | folder called "libs/" and drop files of this zip file into it. In the package explorer you should then |
||
| 10 | have something like this: |
||
| 11 | |||
| 12 | gdx-helloworld |
||
| 13 | -> src/ |
||
| 14 | -> JRE System Library |
||
| 15 | -> libs/ |
||
| 16 | -> armeabi/ |
||
| 17 | - >libandroidgl20.so |
||
| 18 | - >libgdx.so |
||
| 19 | -> armeabi-v7a/ |
||
| 20 | - >libandroidgl20.so |
||
| 21 | - >libgdx.so |
||
| 22 | -> docs/ |
||
| 23 | - > index.html and other files containing the Java Doc. |
||
| 24 | -> gdx.jar |
||
| 25 | -> gdx-backend-android.jar |
||
| 26 | -> gdx-backend-jogl.jar |
||
| 27 | -> gdx-backend-jogl-natives.jar |
||
| 28 | -> gdx-backend-lwjgl.jar |
||
| 29 | -> gdx-backend-lwjgl-natives.jar |
||
| 30 | -> gdx-natives.jar |
||
| 31 | -> gdx-twl.jar |
||
| 32 | -> gdx-sources.jar |
||
| 33 | -> README |
||
| 34 | |||
| 35 | Next right click on the the gdx-helloworld project in the package explorer and select properties. Select |
||
| 36 | "Java Build Path" to the left in the new dialog and then click the Libraries tab. In the libraries tab |
||
| 37 | click "Add Jars", browse to the gdx-helloworld/libs folder and select gdx.jar, gdx-natives.jar, |
||
| 38 | gdx-backend-jogl.jar, and gdx-backend-jogl-natives.jar Now you have added all that's needed for the Java |
||
| 39 | desktop project to compile. |
||
| 40 | |||
| 41 | Create a new package in the "src/" folder of the gdx-helloworld project, say "com.badlogic.helloworld" |
||
| 42 | and create a new class called "HelloWorld" in this package. Here's the source to put into this class: |
||
| 43 | |||
| 44 | =========== CODE =========== |
||
| 45 | package com.badlogic.helloworld; |
||
| 46 | import com.badlogic.gdx.ApplicationListener; |
||
| 47 | |||
| 48 | public class HelloWorld implements ApplicationListener |
||
| 49 | { |
||
| 50 | @Override |
||
| 51 | public void resume() { |
||
| 52 | |||
| 53 | } |
||
| 54 | |||
| 55 | @Override |
||
| 56 | public void resize(int width, int height) { |
||
| 57 | |||
| 58 | } |
||
| 59 | |||
| 60 | @Override |
||
| 61 | public void render() { |
||
| 62 | |||
| 63 | } |
||
| 64 | |||
| 65 | @Override |
||
| 66 | public void pause() { |
||
| 67 | |||
| 68 | } |
||
| 69 | |||
| 70 | @Override |
||
| 71 | public void dispose() { |
||
| 72 | |||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public void create() { |
||
| 77 | |||
| 78 | } |
||
| 79 | } |
||
| 80 | =========== CODE =========== |
||
| 81 | |||
| 82 | Next we need to create a start class that will actually execute the above application on the desktop. Create |
||
| 83 | a new Java class in the same package called "HelloWorldDesktop": |
||
| 84 | =========== CODE =========== |
||
| 85 | package com.badlogic.helloworld; |
||
| 86 | import com.badlogic.gdx.backends.jogl.JoglApplication; |
||
| 87 | |||
| 88 | public class HelloWorldDesktop { |
||
| 89 | public static void main(String[] argv) { |
||
| 90 | new JoglApplication(new HelloWorld(), "Hello World", 480, 320, false); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | Simply start the app by right clicking on the project and selecting Run as.. -> Java Application. You will have |
||
| 95 | to select the HelloWorldDesktop class from the dialog that pops up. |
||
| 96 | |||
| 97 | 2) Setting up the Android project |
||
| 98 | Now we want the above HelloWorld class to run on Android. For this we create a new Android project |
||
| 99 | and call it let's say gdx-helloworld-android. Specify Android 1.5 as the target platform. Specify 3 |
||
| 100 | as the minimum SDK version. As an activity name chose for example HelloWorldAndroid. As a package name |
||
| 101 | use "com.badlogic.helloworld". |
||
| 102 | |||
| 103 | In the manifset file make sure you have this: |
||
| 104 | |||
| 105 | <uses-sdk minSdkVersion="3" targetSdkVersion="8"/> |
||
| 106 | |||
| 107 | This will ensure that you can run on all Android versions to date (1.5 - 2.2). |
||
| 108 | |||
| 109 | Also copy over the contents of this zip file to a folder called "libs/" in your Android project. Note that you |
||
| 110 | only need to copy a subset of the files! Here's how your android project should look like now: |
||
| 111 | |||
| 112 | gdx-helloworld-android |
||
| 113 | -> src/ |
||
| 114 | -> com.badlogic.helloworld/ |
||
| 115 | -> HelloWorldAndroid.java |
||
| 116 | -> gen/ |
||
| 117 | -> Android 1.5 |
||
| 118 | -> assets/ |
||
| 119 | -> libs/ |
||
| 120 | -> armeabi/ |
||
| 121 | -> libandroidgl20.so |
||
| 122 | -> libgdx.so |
||
| 123 | -> armeabi-v7a/ |
||
| 124 | - >libandroidgl20.so |
||
| 125 | - >libgdx.so |
||
| 126 | -> gdx.jar |
||
| 127 | -> gdx-backend-android.jar |
||
| 128 | -> res/ |
||
| 129 | -> AndroidManifset.xml |
||
| 130 | -> default.properties |
||
| 131 | |||
| 132 | Go to the properties of the Android project and select "Java Build Path" again. Add the gdx-helloworld |
||
| 133 | project in the project tab and the gdx.jar and gdx-backend-android.jar in the Libraries tab. You don't have to |
||
| 134 | add the gdx-backend-jogl.jar or gdx-backend-jogl-natives.jar jars as those are only needed for the desktop |
||
| 135 | Java version. |
||
| 136 | |||
| 137 | Now open the HelloWorldAndroid.java file and paste the following code in: |
||
| 138 | |||
| 139 | =========== CODE =========== |
||
| 140 | package com.badlogic.helloworld; |
||
| 141 | |||
| 142 | import android.os.Bundle; |
||
| 143 | import com.badlogic.gdx.backends.android.AndroidApplication; |
||
| 144 | import com.badlogic.gdx.helloworld.HelloWorld; |
||
| 145 | |||
| 146 | public class GDXHelloWorld extends AndroidApplication |
||
| 147 | { |
||
| 148 | @Override |
||
| 149 | public void onCreate(Bundle savedInstanceState) { |
||
| 150 | super.onCreate(savedInstanceState); |
||
| 151 | initialize(new HelloWorld(), false); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | =========== CODE =========== |
||
| 155 | |||
| 156 | Now we are almost ready to start the thing on the device. Open the AndroidManifest.xml and add |
||
| 157 | |||
| 158 | android:configChanges="keyboard|keyboardHidden|orientation" |
||
| 159 | |||
| 160 | to the <activity> tag. Your manifest should look something like this then: |
||
| 161 | |||
| 162 | <?xml version="1.0" encoding="utf-8"?> |
||
| 163 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||
| 164 | package="com.badlogic.helloworld" |
||
| 165 | android:versionCode="1" |
||
| 166 | android:versionName="1.0"> |
||
| 167 | <application android:icon="@drawable/icon" android:label="@string/app_name"> |
||
| 168 | <activity android:name=".HelloWorldAndroid" |
||
| 169 | android:label="@string/app_name" |
||
| 170 | android:configChanges="keyboard|keyboardHidden|orientation"> |
||
| 171 | <intent-filter> |
||
| 172 | <action android:name="android.intent.action.MAIN" /> |
||
| 173 | <category android:name="android.intent.category.LAUNCHER" /> |
||
| 174 | </intent-filter> |
||
| 175 | </activity> |
||
| 176 | |||
| 177 | </application> |
||
| 178 | <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8"/> |
||
| 179 | |||
| 180 | </manifest> |
||
| 181 | |||
| 182 | Now you can start the Activity as you do with any normal android application in eclipse. Et voila, profit! |
||
| 183 | |||
| 184 | You never have to change the android project again unless you add assets. The rest is done in the Java project. |
||
| 185 | Just verify that it works on the device every now and then starting the Activity of the android project. |
||
| 186 | |||
| 187 | You can download both demo projects completely setup (minus the run configurations) at: |
||
| 188 | http://libgdx.googlecode.com/files/gdx-helloworld.zip |
||
| 189 | |||
| 190 | Have fun! |