(Original: http://www.libgdx.cn/topic/45/4-3-libgdx%E5%90%AF%E5%8A%A8%E7%B1%BB%E4%B8%8E%E9%85%8D%E7%BD% AE)
Each platform must have a startup class. This category is independent for each platform. Here we will only introduce android.
** Android **
The main () method is not applicable to Android applications, but an activity is required. Open the android project and find the following code:
Package CN. libgdx. game;
Import Android. OS. Bundle;
Import com. badlogic. GDX. backends. Android. androidapplication;
Import com. badlogic. GDX. backends. Android. androidapplicationconfiguration;
Public class mainactivity extends androidapplication {
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Androidapplicationconfiguration CFG = new androidapplicationconfiguration ();
Cfg. usegl20 = false;
Initialize (New mygdxgame (), CFG );
}
}
Here, the main portal method is the oncreate () method of activity. In an android application, an android application can have multiple activities. However, only one activity can be found in libgdx games. Different Game interfaces are completed in libgdx instead of multiple interfaces. The reason for this is that you also need to create a new OpenGL context to create an activity, which means all resources need to be reloaded.
** Androidmanifest. xml file **
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "cn. libgdx. Game"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Uses-SDK Android: minsdkversion = "5" Android: targetsdkversion = "15"/>
<Application
Android: icon = "@ drawable/ic_launcher"
Android: Label = "@ string/app_name">
<Activity
Android: Name = ". mainactivity"
Android: Label = "@ string/app_name"
Android: screenorientation = "Landscape"
Android: configchanges = "keyboard | keyboardhidden | orientation">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>
Add permission:
<Uses-Permission Android: Name = "android. Permission. record_audio"/>
<Uses-Permission Android: Name = "android. Permission. write_external_storage"/>
<Uses-Permission Android: Name = "android. Permission. Vibrate"/>
(Www.libgdx.cn is copyrighted. If you need to reprint it, indicate the source)
4.3 libgdx startup class and Configuration